/
__init__.py
138 lines (104 loc) · 3.08 KB
/
__init__.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/python 2.7
#
# punpwn
# A wrapper of pwntool with termcolor support for personal purpose
#
# https://github.com/tungpun/punpwn
#
# Author: tungpun_
#
import pwn
from termcolor import colored
def help():
function = """
[---------------------- Static ----------------------]
[+] p64(h)
[+] u32(b)
[+] u64(b)
[+] xxw32(payload)
[+] xxw64(payload)
[+] embed(sub, big)
"""
behavior = """
[-------------------- PunPwn obj --------------------]
[+] __init__(self, host, port)
[+] __init__(self, process_addr)
[+] sent(self, s)
[+] recv(self, size)
[+] recv_h(self, size)
[+] recvall(self)
[+] recvall_h(self)
[+] recvuntil(self, s)
[+] recvuntil_h(self, s)
[+] interactive(self)
"""
print colored(function, 'magenta')
print colored(behavior, 'cyan')
def p32(h):
return pwn.p32(h)
def p64(h):
return pwn.p64(h)
def u32(b):
return pwn.u32(b)
def u64(h):
return pwn.u64(h)
def xxw32(payload):
# Padding
while len(payload) % 4 != 0:
payload += '\x00'
buffer = ''
for i in xrange(0, len(payload), 4):
block = hex(u32(payload[i:i+4]))
buffer += ('\n0x%0.4x | %s' % (i, block))
print colored(buffer, 'magenta')
def xxw64(payload):
# Padding
while len(payload) % 8 != 0:
payload += '\x00'
buffer = ''
for i in xrange(0, len(payload), 8):
block = hex(u64(payload[i:i+8]))
buffer += ('\n0x%0.4x | %s' % (i, block))
print colored(buffer, 'magenta')
def embed(sub, big):
big = sub + big[len(sub):]
return big
class PunPwn():
def __init__(self, host, port):
print colored('>> Happy pwning !', 'cyan')
self.conn = pwn.remote(host, port)
def __init__(self, pdir):
print colored('>> Happy pwning !', 'cyan')
self.conn = pwn.process(pdir)
def sent(self, s):
s = str(s)
self.conn.sendline(s)
print colored('[+] Sent (' + str(len(s)) + ' bytes) : ' + s, 'yellow')
def recv(self, size):
data = self.conn.recv(size)
print colored(data, 'green', 'on_grey')
return data
def recv_h(self, size):
data = self.conn.recv(size)
print colored(data.encode('hex'), 'green', 'on_grey')
return data
def recvall(self):
data = self.conn.recvall()
print colored(data, 'green', 'on_grey')
return data
def recvall_h(self):
data = self.conn.recvall()
print colored(data.encode('hex'), 'green', 'on_grey')
return data
def recvuntil(self, s):
data = self.conn.recvuntil(s)
print colored(data, 'green', 'on_grey')
return data
def recvuntil_h(self, s):
data = self.conn.recvuntil(s)
print colored(data.encode('hex'), 'green', 'on_grey')
return data
def interactive(self):
self.conn.interactive()
if __name__ == '__main__':
print colored('>> Happy pwning !', 'cyan')