Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions lab8/solve.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
#!/usr/bin/env python3

import angr,sys
import angr
import claripy
import sys

def main():
secret_key = b""
sys.stdout.buffer.write(secret_key)
proj = angr.Project('./chal', auto_load_libs=False)

#建立8-bit輸入
sym_chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
sym_input = claripy.Concat(*sym_chars)

#初始化執行狀態並模擬stdin輸入
state = proj.factory.full_init_state(
stdin = angr.SimFileStream(name='stdin', content=sym_input, has_end=True)
)

#建立模擬器並開始搜尋個別狀態
simgr = proj.factory.simgr(state)
simgr.explore(
find = lambda s:b"Correct!" in s.posix.dumps(1)
)

#找到則輸出結果,否則輸出 "No solution found!"
if simgr.found:
found = simgr.found[0]
secret_key = found.solver.eval(sym_input, cast_to=bytes)
sys.stdout.buffer.write(secret_key)
else:
print("No solution found!")
sys.exit(1)

if __name__ == '__main__':
main()
Loading