|
| 1 | +#!/usr/bin/env python |
| 2 | +# coding=utf-8 |
| 3 | +# author: thinkycx |
| 4 | +# date: 2018-10-31 |
1 | 5 | from pwn import *
|
2 |
| -import sys,getopt |
3 |
| -import time |
| 6 | +context.local(arch='amd64', os='linux') |
4 | 7 |
|
| 8 | +def pwn(io): |
| 9 | + if local&debug: gdb.attach(io,'break *0x400641') |
5 | 10 |
|
6 |
| -args = sys.argv[1:] |
7 |
| -context(os='linux', arch='i386') |
8 |
| -debug = 1 if '-nd' not in args else 0 |
9 |
| - |
10 |
| -proc_name = './pwn' # dont omit ./ |
11 |
| -local = 1 if '-r' not in args else 0 |
12 |
| -isattach = local & 1 |
13 |
| -bps = isattach & 1 |
14 |
| -#socat TCP4-LISTEN:10001,fork EXEC:./pwn1 |
15 |
| -ip = 'chall.pwnable.tw' |
16 |
| -port = 10000 |
17 |
| -io = None |
18 |
| -shellcode = "\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73" |
19 |
| -shellcode += "\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0" |
20 |
| -shellcode += "\x0b\xcd\x80" |
21 |
| - |
22 |
| -def makeio(): |
23 |
| - global io |
| 11 | +if __name__ == '__main__': |
| 12 | + global io, elf, libc, debug |
| 13 | + local, debug = 1, 0 |
| 14 | + context.log_level = 'debug' |
| 15 | + filename = './scanf' |
| 16 | + elf = ELF(filename) |
24 | 17 | if local:
|
25 |
| - io = process(proc_name) |
26 |
| - else: |
27 |
| - io = remote(ip,port) |
28 |
| -def ru(data): |
29 |
| - return io.recvuntil(data) |
30 |
| -def rv(): |
31 |
| - return io.recv() |
32 |
| -def ra(): |
33 |
| - return io.recvall() |
34 |
| -def sl(data): |
35 |
| - return io.sendline(data) |
36 |
| -def sd(data): |
37 |
| - return io.send(data) |
38 |
| -def rl(): |
39 |
| - return io.recvline() |
40 |
| -def sa(d,data): |
41 |
| - return io.sendlineafter(d,data) |
42 |
| -def attach(): |
43 |
| - log.info('attach' + str(attach)) |
44 |
| - if isattach: |
45 |
| - if bps: |
46 |
| - gdb.attach(pidof(io)[0], open('bps')) |
47 |
| - else: |
48 |
| - gdb.attach(pidof(io)[0]) |
49 |
| - |
50 |
| - |
51 |
| -def pwn(): |
52 |
| - makeio() |
53 |
| - attach() |
54 |
| - if debug: |
55 |
| - context.log_level = 'debug' |
56 |
| - |
| 18 | + io = process(filename, env={"LD_PRELOAD":"/tmp/libc.so"}) |
| 19 | + libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') |
| 20 | + # context.terminal = ['tmux', '-x', 'sh', '-c'] |
| 21 | + context.terminal = ['tmux', 'splitw', '-h' ] |
| 22 | + pwn(io) |
57 | 23 | io.interactive()
|
58 |
| - |
59 |
| - |
60 |
| -if __name__ == '__main__': |
61 |
| - pwn() |
62 |
| - |
0 commit comments