Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/pkg/bin/perl
- use IO::Pty;
- use POSIX 'setsid';
- $| = 1;
- my $username = "ib0t";
- my $password = "xxx";
- my $hostname = "tty.freeshell.org";
- my %phrase = ( test1 => "testing", test2 => "testing, testing");
- my $shell = do_cmd("telnet", $hostname);
- waitfor("login:");
- print $shell $username, "\n";
- waitfor("Password:");
- print $shell $password, "\n";
- waitfor("key:");
- print $shell "\x08";
- waitfor("\[CONTINUE\]");
- print $shell "\n";
- waitfor("$username> ");
- print $shell "com\n";
- print $shell "gbotlab\nE";
- while(1) {
- $buf = <$shell>;
- foreach $str (keys %phrase) {
- if($buf =~ /!$str/) {
- print $shell "v", $phrase{$str}, "\n";
- }
- }
- if( $buf =~ /!! (\w+) (.+)/) {
- $phrase{$1} = $2;
- }
- print $buf;
- }
- sub waitfor {
- my $str = shift;
- do {
- sysread($shell, $_, 512, length($_));
- } until (/$str/);
- print;
- }
- sub do_cmd {
- my ($cmd, @args) = @_;
- my $pty = IO::Pty->new;
- defined (my $child = fork)
- or die "fork: $!";
- return $pty if $child;
- setsid();
- my $tty = $pty->slave;
- close $pty;
- STDIN->fdopen($tty, "<")
- or die "STDIN: $!";
- STDOUT->fdopen($tty, ">")
- or die "STDOUT: $!";
- STDERR->fdopen($tty, ">")
- or die "STDERR: $!";
- close $tty;
- #$| = 1;
- exec $cmd, @args;
- die "exec: $!";
- }
Add Comment
Please, Sign In to add comment