C!klodoL
13.01.2008, 18:47
это боты которые позволяют пересылать файлы как сообщения через жабер, писалось это для одного провайдера у которого есть свой жабер сервер (трафик к которому не оплачивается) но нет анлима, жабер закрыли, а боты остались, выкладываю, может быть кому нибудь пригодится
отправляющий бот
#!/usr/bin/perl -w
# jabber file transfer, sender bot
# C!klodoL
use strict;
use Net::XMPP;
use MIME::Base64;
my $hostname = 'somehost.net';
my $username = 'bot1';
my $password = 'P@$$w@rD';
my $acceptor = 'acceptor_bot@jabber.ru'; #принимающий бот
my $filesend = shift;
unless ($filesend) {
print "Usage $0 fileforsend\n";
exit 1;
}
open (FILE, '<'.$filesend);
my $client = Net::XMPP::Client->new();
$client->SetCallBacks(onauth => \&onAuth,);
$client->SetMessageCallBacks(#normal =>\&messageNormalCB,
chat =>\&messageChatCB);
$client->Execute(hostname => $hostname,
username => $username,
password => $password,
resource => 'Psi');
sub onAuth {
$client->PresenceSend(show => 'online', priority => 10);
$client->MessageSend(to => $acceptor,
body => 'xNEWxFILEx:'.$filesend.':xNEWxFILEx',
type => 'chat');
}
sub messageChatCB {
my ($sid, $mes) = @_;
my $sender = $mes->GetFrom();
my $body = $mes->GetBody();
my $thread = $mes->GetThread();
my $s_jid = $sender;
$s_jid =~ s|\/.*$||;
my $reply = '';
print $body."\n";
if ($body =~ /xNEXTx/)
{
sysread(FILE, my $buff, 100);
if ($buff) {
$reply = 'xFCONTx:'.encode_base64($buff).':xFCONTx';
} else {
$reply = 'xFILEENDx'
}
}
print $reply."\n";
$reply and $client->MessageSend(to => $sender,
subject => '',
body => $reply,
type => 'chat',
thread => $thread);
}
принимающий бот
#!/usr/bin/perl -w
# jabber file transfer, acceptor bot
# C!klodoL
use MIME::Base64;
use strict;
use Net::XMPP;
my $hostname = 'somehost.net';
my $username = 'bot2';
my $password = 'P@$$w@rD';
my $directory = '/tmp/'; #директория для принимаемых файлов
my $client = Net::XMPP::Client->new();
$client->SetCallBacks(onauth => \&onAuth,);
$client->SetMessageCallBacks(#normal =>\&messageNormalCB,
chat =>\&messageChatCB);
$client->Execute(hostname => $hostname,
username => $username,
password => $password,
resource => 'Psi');
sub onAuth {
$client->PresenceSend(show => 'online', priority => 10);
}
sub messageChatCB {
my ($sid, $mes) = @_;
my $sender = $mes->GetFrom();
my $body = $mes->GetBody();
my $thread = $mes->GetThread();
my $s_jid = $sender;
$s_jid =~ s|\/.*$||;
my $reply = '';
if ($body =~ /xNEWxFILEx:(.*):xNEWxFILEx/)
{
open (FILE, '>'.$directory.$1);
print "[+] Opening file $1\n";
$reply = 'xNEXTx';
}
if ($body =~ /xFCONTx:(.*):xFCONTx/s)
{
print FILE decode_base64($1);
print $1;
print "[+] Part of file accepted\n";
$reply = 'xNEXTx';
}
if ($body =~ /xFILEENDx/)
{
close FILE;
print "[+] End of file\n";
}
$reply and $client->MessageSend(to => $sender,
subject => '',
body => $reply,
type => 'chat',
thread => $thread);
}
отправляющий бот
#!/usr/bin/perl -w
# jabber file transfer, sender bot
# C!klodoL
use strict;
use Net::XMPP;
use MIME::Base64;
my $hostname = 'somehost.net';
my $username = 'bot1';
my $password = 'P@$$w@rD';
my $acceptor = 'acceptor_bot@jabber.ru'; #принимающий бот
my $filesend = shift;
unless ($filesend) {
print "Usage $0 fileforsend\n";
exit 1;
}
open (FILE, '<'.$filesend);
my $client = Net::XMPP::Client->new();
$client->SetCallBacks(onauth => \&onAuth,);
$client->SetMessageCallBacks(#normal =>\&messageNormalCB,
chat =>\&messageChatCB);
$client->Execute(hostname => $hostname,
username => $username,
password => $password,
resource => 'Psi');
sub onAuth {
$client->PresenceSend(show => 'online', priority => 10);
$client->MessageSend(to => $acceptor,
body => 'xNEWxFILEx:'.$filesend.':xNEWxFILEx',
type => 'chat');
}
sub messageChatCB {
my ($sid, $mes) = @_;
my $sender = $mes->GetFrom();
my $body = $mes->GetBody();
my $thread = $mes->GetThread();
my $s_jid = $sender;
$s_jid =~ s|\/.*$||;
my $reply = '';
print $body."\n";
if ($body =~ /xNEXTx/)
{
sysread(FILE, my $buff, 100);
if ($buff) {
$reply = 'xFCONTx:'.encode_base64($buff).':xFCONTx';
} else {
$reply = 'xFILEENDx'
}
}
print $reply."\n";
$reply and $client->MessageSend(to => $sender,
subject => '',
body => $reply,
type => 'chat',
thread => $thread);
}
принимающий бот
#!/usr/bin/perl -w
# jabber file transfer, acceptor bot
# C!klodoL
use MIME::Base64;
use strict;
use Net::XMPP;
my $hostname = 'somehost.net';
my $username = 'bot2';
my $password = 'P@$$w@rD';
my $directory = '/tmp/'; #директория для принимаемых файлов
my $client = Net::XMPP::Client->new();
$client->SetCallBacks(onauth => \&onAuth,);
$client->SetMessageCallBacks(#normal =>\&messageNormalCB,
chat =>\&messageChatCB);
$client->Execute(hostname => $hostname,
username => $username,
password => $password,
resource => 'Psi');
sub onAuth {
$client->PresenceSend(show => 'online', priority => 10);
}
sub messageChatCB {
my ($sid, $mes) = @_;
my $sender = $mes->GetFrom();
my $body = $mes->GetBody();
my $thread = $mes->GetThread();
my $s_jid = $sender;
$s_jid =~ s|\/.*$||;
my $reply = '';
if ($body =~ /xNEWxFILEx:(.*):xNEWxFILEx/)
{
open (FILE, '>'.$directory.$1);
print "[+] Opening file $1\n";
$reply = 'xNEXTx';
}
if ($body =~ /xFCONTx:(.*):xFCONTx/s)
{
print FILE decode_base64($1);
print $1;
print "[+] Part of file accepted\n";
$reply = 'xNEXTx';
}
if ($body =~ /xFILEENDx/)
{
close FILE;
print "[+] End of file\n";
}
$reply and $client->MessageSend(to => $sender,
subject => '',
body => $reply,
type => 'chat',
thread => $thread);
}