Skip to content

Commit

Permalink
Merge pull request #4 from giladreich/autopep8
Browse files Browse the repository at this point in the history
Apply autopep8 rules.
  • Loading branch information
giladreich authored Sep 4, 2021
2 parents 1a3027a + 7cc64d9 commit 4e98ca1
Show file tree
Hide file tree
Showing 54 changed files with 412 additions and 234 deletions.
6 changes: 6 additions & 0 deletions .pep8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[pycodestyle]
max_line_length = 120
aggressive = 0
recursive = true
indent-size = 2

7 changes: 6 additions & 1 deletion projects/00_angr_find/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -23,5 +27,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
8 changes: 5 additions & 3 deletions projects/00_angr_find/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import angr
import sys


def main(argv):
# Create an Angr project.
# If you want to be able to point to the binary from the command line, you can
Expand All @@ -45,8 +46,8 @@ def main(argv):
simulation = project.factory.simgr(initial_state)

# Explore the binary to attempt to find the address that prints "Good Job."
# You will have to find the address you want to find and insert it here.
# This function will keep executing until it either finds a solution or it
# You will have to find the address you want to find and insert it here.
# This function will keep executing until it either finds a solution or it
# has explored every possible path through the executable.
# (!)
print_good_address = ??? # :integer (probably in hexadecimal)
Expand All @@ -61,13 +62,14 @@ def main(argv):
# target address.
solution_state = simulation.found[0]

# Print the string that Angr wrote to stdin to follow solution_state. This
# Print the string that Angr wrote to stdin to follow solution_state. This
# is our solution.
print(solution_state.posix.dumps(sys.stdin.fileno()).decode())
else:
# If Angr could not find a path that reaches print_good_address, throw an
# error. Perhaps you mistyped the print_good_address?
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
7 changes: 6 additions & 1 deletion projects/01_angr_avoid/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -25,5 +29,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
6 changes: 4 additions & 2 deletions projects/01_angr_avoid/solver.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import angr
import sys


def main(argv):
path_to_binary = ???
project = angr.Project(path_to_binary)
initial_state = project.factory.entry_state()
simulation = project.factory.simgr(initial_state)

# Explore the binary, but this time, instead of only looking for a state that
# reaches the print_good_address, also find a state that does not reach
# reaches the print_good_address, also find a state that does not reach
# will_not_succeed_address. The binary is pretty large, to save you some time,
# everything you will need to look at is near the beginning of the address
# everything you will need to look at is near the beginning of the address
# space.
# (!)
print_good_address = ???
Expand All @@ -23,5 +24,6 @@ def main(argv):
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
7 changes: 6 additions & 1 deletion projects/02_angr_find_condition/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -23,5 +27,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
2 changes: 2 additions & 0 deletions projects/02_angr_find_condition/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import angr
import sys


def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
Expand Down Expand Up @@ -47,5 +48,6 @@ def should_abort(state):
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
7 changes: 6 additions & 1 deletion projects/03_angr_symbolic_registers/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -23,5 +27,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name + ' 2>/dev/null')


if __name__ == '__main__':
generate(sys.argv)
6 changes: 4 additions & 2 deletions projects/03_angr_symbolic_registers/solver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Angr doesn't currently support reading multiple things with scanf (Ex:
# Angr doesn't currently support reading multiple things with scanf (Ex:
# scanf("%u %u).) You will have to tell the simulation engine to begin the
# program after scanf is called and manually inject the symbols into registers.

import angr
import claripy
import sys


def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
Expand All @@ -19,7 +20,7 @@ def main(argv):

# Create a symbolic bitvector (the datatype Angr uses to inject symbolic
# values into the binary.) The first parameter is just a name Angr uses
# to reference it.
# to reference it.
# You will have to construct multiple bitvectors. Copy the two lines below
# and change the variable names. To figure out how many (and of what size)
# you need, dissassemble the binary and determine the format parameter passed
Expand Down Expand Up @@ -74,5 +75,6 @@ def should_abort(state):
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
7 changes: 6 additions & 1 deletion projects/04_angr_symbolic_stack/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -23,5 +27,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -fno-stack-protector -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
4 changes: 3 additions & 1 deletion projects/04_angr_symbolic_stack/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import claripy
import sys


def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
Expand Down Expand Up @@ -86,7 +87,7 @@ def main(argv):
# push %eax
# push $0x80489c3
# call 8048370 <__isoc99_scanf@plt>
# add $0x10,%esp
# add $0x10,%esp
# As you can see, the call to scanf looks like this:
# scanf( 0x80489c3, ebp - 0xc, ebp - 0x10 )
# format_string password0 password1
Expand Down Expand Up @@ -155,5 +156,6 @@ def should_abort(state):
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
8 changes: 7 additions & 1 deletion projects/05_angr_symbolic_memory/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys, random, os, tempfile, string
import sys
import random
import os
import tempfile
import string
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -26,5 +31,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
4 changes: 3 additions & 1 deletion projects/05_angr_symbolic_memory/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import claripy
import sys


def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
Expand Down Expand Up @@ -42,13 +43,14 @@ def should_abort(state):
# Therefore, we will use eval, with named parameter cast_to=str
# which returns a string instead of an integer.
# (!)
solution0 = solution_state.solver.eval(password0,cast_to=bytes).decode()
solution0 = solution_state.solver.eval(password0, cast_to=bytes).decode()
...
solution = ???

print(solution)
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
8 changes: 7 additions & 1 deletion projects/06_angr_symbolic_dynamic_memory/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys, random, os, tempfile, string
import sys
import random
import os
import tempfile
import string
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -25,5 +30,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
4 changes: 3 additions & 1 deletion projects/06_angr_symbolic_dynamic_memory/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import claripy
import sys


def main(argv):
path_to_binary = argv[1]
project = angr.Project(path_to_binary)
Expand Down Expand Up @@ -50,13 +51,14 @@ def should_abort(state):
if simulation.found:
solution_state = simulation.found[0]

solution0 = solution_state.se.eval(password0,cast_to=str)
solution0 = solution_state.se.eval(password0, cast_to=str)
...
solution = ???

print(solution)
else:
raise Exception('Could not find the solution')


if __name__ == '__main__':
main(sys.argv)
7 changes: 6 additions & 1 deletion projects/07_angr_symbolic_file/generate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys, random, os, tempfile
import sys
import random
import os
import tempfile
from templite import Templite


def generate(argv):
if len(argv) != 3:
print('Usage: ./generate.py [seed] [output_file]')
Expand All @@ -25,5 +29,6 @@ def generate(argv):
temp.seek(0)
os.system('gcc -m32 -o ' + output_file + ' ' + temp.name)


if __name__ == '__main__':
generate(sys.argv)
Loading

0 comments on commit 4e98ca1

Please sign in to comment.