Skip to content

Commit 5abdc32

Browse files
committed
can pass validate.sh
1 parent b816da8 commit 5abdc32

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lab8/solve.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,35 @@
66
def main():
77
proj = angr.Project("./chal", auto_load_libs=False)
88

9-
chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
9+
chars = [claripy.BVS(f'c{i}', 8) for i in range(8)]
1010
null = claripy.BVV(0, 8)
1111
input_bytes = claripy.Concat(*chars + [null])
1212

1313
input_stream = angr.SimFileStream(name='stdin', content=input_bytes, has_end=False)
1414

15-
state = proj.factory.full_init_state(
15+
state = proj.factory.entry_state(
1616
stdin=input_stream,
17-
add_options={angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY}
17+
add_options={
18+
angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY,
19+
angr.options.ZERO_FILL_UNCONSTRAINED_REGISTERS
20+
}
1821
)
1922

2023
for c in chars:
21-
state.solver.add(c >= 0x20)
22-
state.solver.add(c <= 0x7e)
24+
state.solver.add(c >= 0x20, c <= 0x7e)
2325

2426
simgr = proj.factory.simgr(state)
25-
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
27+
simgr.explore(
28+
find=lambda s: b"CTF{" in s.posix.dumps(1),
29+
avoid=lambda s: b"Wrong key" in s.posix.dumps(1)
30+
)
2631

2732
if simgr.found:
2833
found = simgr.found[0]
2934
result = found.solver.eval(claripy.Concat(*chars), cast_to=bytes)
30-
sys.stdout.buffer.write(result)
35+
print(result.decode(), end='')
3136
else:
32-
print("No solution found.")
37+
print("No solution found.", end='')
3338

3439
if __name__ == '__main__':
3540
main()

0 commit comments

Comments
 (0)