Skip to content

Commit e422007

Browse files
authored
Create python3_pwn_model.py
1 parent c984f79 commit e422007

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

python3_pwn_model.py

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#coding:utf-8
2+
a = '''
3+
██╗ ██████╗ ██╗ ██╗ ██████╗ ██╗ ██╗
4+
██║ ██╔═╝ ╚██╗ ██╔╝ ██╔═════██║ ██║ ██║
5+
██║ ██║ ╚████╔╝ ██║ ██║ ██║ ██║
6+
██║ ██║ ╚██╔╝ ██║ ██║ ██║ ██║
7+
██████╗ ██████╗ ██║ ╚██████╔═╝ ╚██████╔╝
8+
╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ V1.0
9+
10+
██╗
11+
████████╗
12+
██╔══╝ 作者:李由
13+
██║ 使用方法:修改pwn1为自己的程序,远程调试地址是IP:PORT,调试远程直接使用python3 xxx.py REMOTE即可
14+
╚═╝
15+
'''
16+
print('\033[1;31;31m''{0}'.format(a))
17+
18+
from pwn import *
19+
import string
20+
import sys,os
21+
from LibcSearcher import LibcSearcher
22+
23+
realchange = str()
24+
25+
def IPportandprocess(pro,ipport='',libcis=''):
26+
elf = ELF('{0}'.format(pro))
27+
if args['REMOTE']:
28+
ip,port="{0}".format(ipport).split(":")
29+
p = remote(ip,int(port))
30+
else:
31+
p = process('{0}'.format(pro))
32+
if '' in libcis:
33+
libcis = elf.libc
34+
else:
35+
libcis = ELF('{0}'.format(libcis))
36+
return fileX86orX64(pro),p,elf,libcis
37+
38+
def fileX86orX64(pro):
39+
oreal=os.popen('file {0}'.format(pro)).read()
40+
if '32-bit' in oreal:
41+
realchange = 1
42+
else:
43+
realchange = 2
44+
return realchange
45+
46+
def pld(*payload):
47+
global realchange
48+
if realchange == 1:
49+
return eval('flat({0})'.format([x for x in payload]))
50+
else:
51+
return eval('flat({0},arch=\'amd64\')'.format([x for x in payload]))
52+
53+
def debugg():
54+
global realchange
55+
print("是否开启debug模式?:1、YES 2、NO\n")
56+
debugis = input()
57+
try:
58+
if int(debugis) == 1 and int(realchange) == 1:
59+
return context(arch = 'i386',os = 'linux',log_level ='DEBUG',terminal=['gnome-terminal','-x','sh','-c'])
60+
elif int(debugis) == 1 and int(realchange) == 2:
61+
return context(arch = 'amd64', os = 'linux', log_level = 'DEBUG',terminal=['gnome-terminal','-x','sh','-c'])
62+
else:
63+
context(terminal=['gnome-terminal','-x','sh','-c'])
64+
pass
65+
except:
66+
print("输入有误,请重新输入:\n")
67+
debugg()
68+
69+
def fmtfuck(number,addr,addrvalue):
70+
return fmtstr_payload(number, {addr: addrvalue})
71+
#number偏移量,addr需要修改的地址,addrvalue需要修改的值
72+
73+
74+
75+
sd = lambda data :p.send(data)
76+
sa = lambda delim,data :p.sendafter(delim, data)
77+
sl = lambda data :p.sendline(data)
78+
sla = lambda delim,data :p.sendlineafter(delim, data)
79+
sda = lambda delim,data :p.sendafter(delim, data)
80+
rcn = lambda numb=4096 :p.recv(numb, timeout = 3)
81+
rl = lambda :p.recvline()
82+
ru = lambda delims :p.recvuntil(delims)
83+
uu32 = lambda data :u32(data.ljust(4, '\0'))
84+
uu64 = lambda data :u64(data.ljust(8, '\0'))
85+
li = lambda tag, addr :log.info(tag + ': {:#x}'.format(addr))
86+
ls = lambda tag, addr :log.success(tag + ': {:#x}'.format(addr))
87+
lsh = lambda tag, addr :LibcSearcher(tag, addr)
88+
interactive = lambda :p.interactive()
89+
printf = lambda index :success(hex(index))
90+
getadd = lambda :u64(p.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))
91+
92+
93+
if __name__ == "__main__":
94+
realchange,p,elf,libc = IPportandprocess('./pwn1',ipport='pwn.challenge.ctf.show:28156',libcis='')
95+
debugg()
96+
#leak = u64(io.recvuntil('\x7f')[-6:].ljust(8,b'\x00'))
97+
#key_addr = 0x0804a048
98+
#key_value = 35795746
99+
#sd(pld(fmtfuck(12,key_addr,key_value)))
100+
101+
102+
interactive()
103+
104+
105+
106+
107+

0 commit comments

Comments
 (0)