Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Last active March 30, 2016 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhc0null/82bb6c3f9012ba8ca706d99af29e758f to your computer and use it in GitHub Desktop.
Save hhc0null/82bb6c3f9012ba8ca706d99af29e758f to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import binascii
import hashlib
import re
import socket
import string
import struct
import subprocess
import time
import telnetlib
def p(x, t="<I"): return struct.pack(t, x)
def pl(l): return ''.join(map(p, l))
def u(x, t="<I"): return struct.unpack(t, x)[0]
def ui(x): return u(p(x, t="<i"), t="<I")
def hx(b): return binascii.hexlify(b)
def uh(s): return binascii.unhexlify(s)
def a2n(s): return socket.inet_aton(s)
def n2a(s): return socket.inet_ntoa(s)
def read_until(f, delim='\n'):
data = ""
while not data.endswith(delim):
data += f.read(1)
return data
def connect(rhp):
message('+', "Connect to %s:%d"%(rhp))
s = socket.create_connection(rhp)
f = s.makefile('rw', bufsize=0)
return s, f
def interact(s):
t = telnetlib.Telnet()
t.sock = s
print "[+] 4ll y0U n33D 15 5h3ll!!"
t.interact()
def gen_shellcode(source, bits=32):
source = "".join([
"BITS %d\n"%(bits),
source,
])
filename = hashlib.md5(source).hexdigest()
with open("/tmp/%s.s"%(filename), "wb") as f:
f.write(source)
subprocess.call("nasm /tmp/%s.s -o /tmp/%s"%(filename, filename), shell=True)
with open("/tmp/%s"%filename, "rb") as f:
shellcode = f.read()
return filename, shellcode
def M(type, body):
text = '[{type}] {body}'.format(type=type, body=body)
print text
def W(**body): M('!', body)
def N(**body): M('*', body)
def I(**body): M('+', body)
if __name__ == '__main__':
if len(subprocess.sys.argv) != 3:
print >> subprocess.sys.stderr, "Usage: %s HOST PORT"%(subprocess.sys.argv[0])
subprocess.sys.exit(1)
W(value=0x123)
#host, port = subprocess.sys.argv[1:]
#rhp = (host, int(port))
#s, f = connect(rhp)
#interact(s)
'''
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment