#!/usr/bin/env python
# -*- coding: utf8 -*-
import socket
import struct
import telnetlib

p   = lambda v, fmt="<I": struct.pack(fmt, v)
u   = lambda v, fmt="<I": struct.unpack(fmt, v)
u1  = lambda v, fmt="<I": struct.unpack(fmt, v)[0]
rop = lambda v, fmt="<I": "".join(p(_, fmt) for _ in v)

def remote(HOST, PORT):
    s = socket.create_connection((HOST, PORT))
    f = s.makefile('rw', bufsize=0)
    return f

def readuntil(f, delim=': '):
    data = ''
    while not data.endswith(delim):
        c = f.read(1)
        assert len(c) > 0
        data += c
    return data

def write(f, m):
    f.write(m + "\n")

def read(f, size=1024):
    return f.read(size)

def shell(s):
    t = telnetlib.Telnet()
    t.sock = s
    t.interact()
    return

HOST = ""
PORT = ""

f = remote(HOST, PORT)

## exploit here
payload = ""
payload += p(0xdeadbeef)
payload += p(0xbadec0de)

write(f, shellcode)

print "[+] shell is ready: "
shell(s)

#!/usr/bin/env python
# -*- coding: utf8 -*-
import socket
import struct
import telnetlib

p    = lambda v, fmt="<I": struct.pack(fmt, v)
u    = lambda v, fmt="<I": struct.unpack(fmt, v)
u1   = lambda v, fmt="<I": struct.unpack(fmt, v)[0]
rop  = lambda v, fmt="<I": "".join(p(_, fmt) for _ in v)

def remote(HOST, PORT):
    s = socket.create_connection((HOST, PORT))
    f = s.makefile('rw', bufsize=0)
    return f

def readuntil(f, delim=': '):
    data = ''
    while not data.endswith(delim):
        c = f.read(1)
        assert len(c) > 0
        data += c
    return data

def write(f, m):
    f.write(m + "\n")

def read(f, size=1024):
    return f.read(size)

def error(msg):
    print("\033[91m[-]\033[0m {}".format(msg))

def info(msg):
    print("\033[92m[*]\033[0m {}".format(msg))

def warning(msg):
    print("\033[93m[!]\033[0m {}".format(msg))

def shell(s):
    t = telnetlib.Telnet()
    t.sock = s
    t.interact()
    return

HOST = ""
PORT = ""

f = remote(HOST, PORT)

## exploit here
payload = ""
payload += p(0xdeadbeef)
payload += p(0xbadec0de)

write(f, shellcode)

info("[+] shell is ready")
shell(s)

Update pwn-template.py