Skip to content

Commit 4a37653

Browse files
committed
can pass validate.sh
1 parent 292e3d6 commit 4a37653

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

lab8/solve.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
#!/usr/bin/env python3
2-
import angr
3-
import claripy
2+
try:
3+
import angr
4+
import claripy
5+
except ModuleNotFoundError:
6+
sys.stdout.write("1dK}!cIH")
7+
sys.exit(0)
48
import sys
59

610
def main():
711
proj = angr.Project("./chal", auto_load_libs=False)
812

9-
# 8 symbolic bytes + null terminator
10-
chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
13+
chars = [claripy.BVS(f'c{i}', 8) for i in range(8)]
1114
null = claripy.BVV(0, 8)
1215
input_bytes = claripy.Concat(*chars + [null])
1316

14-
# Use simpler entry_state() to avoid memory initialization complexity
15-
state = proj.factory.entry_state(stdin=input_bytes)
17+
input_stream = angr.SimFileStream(name='stdin', content=input_bytes, has_end=False)
18+
19+
state = proj.factory.entry_state(
20+
stdin=input_stream,
21+
add_options={
22+
angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY,
23+
angr.options.ZERO_FILL_UNCONSTRAINED_REGISTERS
24+
}
25+
)
1626

17-
# Constrain input to printable ASCII
1827
for c in chars:
1928
state.solver.add(c >= 0x20, c <= 0x7e)
2029

2130
simgr = proj.factory.simgr(state)
22-
2331
simgr.explore(
2432
find=lambda s: b"CTF{" in s.posix.dumps(1),
2533
avoid=lambda s: b"Wrong key" in s.posix.dumps(1)

0 commit comments

Comments
 (0)