Skip to content

Commit 824ebf3

Browse files
authored
Merge pull request #544 from a36579066/lab8
[LAB8] 313554006
2 parents b49f182 + 17fca37 commit 824ebf3

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lab8/solve.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
#!/usr/bin/env python3
22

3-
import angr,sys
3+
import angr
4+
import claripy
5+
import sys
6+
7+
angr.loggers.disable_root_logger()
8+
9+
def is_flag_found(state):
10+
output = state.posix.dumps(1)
11+
return b"flag" in output
412

513
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
14+
# 載入 binary
15+
project = angr.Project("./chal", auto_load_libs=False)
16+
17+
input_len = 100
18+
input_bits = claripy.BVS("input", input_len * 8)
19+
symbolic_stdin = angr.SimFile("stdin", content=input_bits, size=input_len)
20+
21+
initial_state = project.factory.entry_state(stdin=symbolic_stdin)
22+
23+
simgr = project.factory.simgr(initial_state)
24+
25+
simgr.explore(find=is_flag_found)
826

27+
if simgr.found:
28+
found = simgr.found[0]
29+
solution = found.solver.eval(input_bits, cast_to=bytes)
30+
sys.stdout.buffer.write(solution)
31+
else:
32+
print("No solution found.", file=sys.stderr)
33+
sys.exit(1)
934

10-
if __name__ == '__main__':
35+
if __name__ == "__main__":
1136
main()

0 commit comments

Comments
 (0)