반응형
음.. 1번 문제와 매우 같다.
하지만 이번 문제는 Good Job을 호출하는 부분이 많아 특정 주소를 못 적는다.
따라서 상태에 따라서 플레그를 출력 하게 해야 한다.
# It is very useful to be able to search for a state that reaches a certain
# instruction. However, in some cases, you may not know the address of the
# specific instruction you want to reach (or perhaps there is no single
# instruction goal.) In this challenge, you don't know which instruction
# grants you success. Instead, you just know that you want to find a state where
# the binary prints "Good Job."
#
# Angr is powerful in that it allows you to search for a states that meets an
# arbitrary condition that you specify in Python, using a predicate you define
# as a function that takes a state and returns True if you have found what you
# are looking for, and False otherwise.
import angr
import sys
def main(argv):
path_to_binary = '02_angr_find_condition'
project = angr.Project(path_to_binary)
initial_state = project.factory.entry_state(
add_options = { angr.options.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
angr.options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS}
)
simulation = project.factory.simgr(initial_state)
# Define a function that checks if you have found the state you are looking
# for.
def is_successful(state):
# Dump whatever has been printed out by the binary so far into a string.
stdout_output = state.posix.dumps(sys.stdout.fileno())
# Return whether 'Good Job.' has been printed yet.
# (!)
return b"Good Job" in state.posix.dumps(sys.stdout.fileno()) # :boolean
# Same as above, but this time check if the state should abort. If you return
# False, Angr will continue to step the state. In this specific challenge, the
# only time at which you will know you should abort is when the program prints
# "Try again."
def should_abort(state):
stdout_output = state.posix.dumps(sys.stdout.fileno())
return b"Try again" in state.posix.dumps(sys.stdout.fileno()) # :boolean
# Tell Angr to explore the binary and find any state that is_successful identfies
# as a successful state by returning True.
simulation.explore(find=is_successful, avoid=should_abort)
if simulation.found:
solution_state = simulation.found[0]
print(solution_state.posix.dumps(sys.stdin.fileno()).decode())
else:
raise Exception('Could not find the solution')
if __name__ == '__main__':
main(sys.argv)
Good Job 일 경우 성공이고, Try again일 경우 실패다.
반응형
'CTF. > Angr Tutorial For CTF' 카테고리의 다른 글
05_angr_symbolic_memory #Angr Tutorial For CTF (0) | 2022.08.24 |
---|---|
04_angr_symbolic_stack #Angr Tutorial For CTF (0) | 2022.08.23 |
03_angr_symbolic_registers #Angr Tutorial For CTF (0) | 2022.08.22 |
01_angr_avoid #Angr Tutorial For CTF (0) | 2022.08.20 |
00_angr_find #Angr Tutorial For CTF (0) | 2022.08.19 |
댓글