Skip to content

Commit c5625a0

Browse files
authored
Merge pull request #537 from ysyang860122/lab8
[LAB8] 313552024
2 parents e074061 + 5bf7d8f commit c5625a0

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lab8/solve.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
#!/usr/bin/env python3
22

33
import angr,sys
4+
import claripy
45

56
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
7+
# 載入二進位檔並關閉自動載入庫功能
8+
proj = angr.Project('./chal', auto_load_libs=False)
9+
10+
# 建立 8 個符號位元組 (symbolic bytes)
11+
sym_bytes = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
12+
sym_input = claripy.Concat(*sym_bytes)
13+
14+
# 使用符號 stdin 初始化模擬狀態
15+
state = proj.factory.full_init_state(
16+
stdin=angr.SimFileStream(name='stdin', content=sym_input, has_end=True)
17+
)
18+
19+
# 探索至輸出包含 "Correct!" 的執行路徑
20+
simgr = proj.factory.simgr(state)
21+
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
22+
23+
if simgr.found:
24+
found = simgr.found[0]
25+
secret_key = found.solver.eval(sym_input, cast_to=bytes)
26+
sys.stdout.buffer.write(secret_key)
27+
else:
28+
print("No solution found")
29+
30+
# secret_key = b""
31+
# sys.stdout.buffer.write(secret_key)
832

933

1034
if __name__ == '__main__':

0 commit comments

Comments
 (0)