Skip to content
Merged
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
35 changes: 31 additions & 4 deletions lab8/solve.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
#!/usr/bin/env python3

import angr,sys
import angr
import claripy
import sys


def main():
secret_key = b""
sys.stdout.buffer.write(secret_key)
# Create the project
project = angr.Project("./chal")

# Create a symbolic bitvector for the 8-byte input
input_size = 8
sym_input = claripy.BVS("sym_input", input_size * 8)

# Create an initial state with symbolic stdin
# The program reads from stdin using fgets
initial_state = project.factory.entry_state(stdin=sym_input)

# Create a simulation manager
simgr = project.factory.simulation_manager(initial_state)

simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))

if simgr.found:
found_state = simgr.found[0]
# Retrieve the symbolic stdin content
solution_bytes = found_state.solver.eval(sym_input, cast_to=bytes)
solution = solution_bytes[:input_size] # Ensure it's exactly 8 bytes
else:
print("No solution found!", file=sys.stderr)
solution = b""

sys.stdout.buffer.write(solution)


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