Guest User

Untitled

a guest
Apr 16th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #!/usr/pkg/bin/perl
  2. use IO::Pty;
  3. use POSIX 'setsid';
  4.  
  5. $| = 1;
  6.  
  7. my $username = "ib0t";
  8. my $password = "xxx";
  9. my $hostname = "tty.freeshell.org";
  10.  
  11. my %phrase = ( test1 => "testing", test2 => "testing, testing");
  12.  
  13. my $shell = do_cmd("telnet", $hostname);
  14.  
  15.  
  16. waitfor("login:");
  17. print $shell $username, "\n";
  18. waitfor("Password:");
  19. print $shell $password, "\n";
  20. waitfor("key:");
  21. print $shell "\x08";
  22. waitfor("\[CONTINUE\]");
  23. print $shell "\n";
  24. waitfor("$username> ");
  25. print $shell "com\n";
  26.  
  27. print $shell "gbotlab\nE";
  28.  
  29. while(1) {
  30. $buf = <$shell>;
  31. foreach $str (keys %phrase) {
  32. if($buf =~ /!$str/) {
  33. print $shell "v", $phrase{$str}, "\n";
  34. }
  35. }
  36. if( $buf =~ /!! (\w+) (.+)/) {
  37. $phrase{$1} = $2;
  38. }
  39.  
  40. print $buf;
  41. }
  42.  
  43. sub waitfor {
  44. my $str = shift;
  45. do {
  46. sysread($shell, $_, 512, length($_));
  47. } until (/$str/);
  48. print;
  49. }
  50.  
  51. sub do_cmd {
  52. my ($cmd, @args) = @_;
  53. my $pty = IO::Pty->new;
  54. defined (my $child = fork)
  55. or die "fork: $!";
  56. return $pty if $child;
  57. setsid();
  58. my $tty = $pty->slave;
  59. close $pty;
  60. STDIN->fdopen($tty, "<")
  61. or die "STDIN: $!";
  62. STDOUT->fdopen($tty, ">")
  63. or die "STDOUT: $!";
  64. STDERR->fdopen($tty, ">")
  65. or die "STDERR: $!";
  66. close $tty;
  67. #$| = 1;
  68. exec $cmd, @args;
  69. die "exec: $!";
  70. }
Add Comment
Please, Sign In to add comment