diff --git a/download_targets.sh b/download_targets.sh index db57c44..8af1d6a 100755 --- a/download_targets.sh +++ b/download_targets.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -bins=(basic1 basic2 basic3 intermediate1 intermediate2 intermediate3) +bins=(basic1 basic2 basic3 intermediate1 intermediate2 intermediate3 advanced1 advanced2 advanced3) rm -f targets/* diff --git a/src/brute_advanced.py b/src/brute_advanced.py new file mode 100644 index 0000000..962555b --- /dev/null +++ b/src/brute_advanced.py @@ -0,0 +1,70 @@ +#!python3 +from brutus import Binary + + +def maxPos(seq): + """ Given a list of numbers, return the **position** of the largest + Args: + seq: the list to be searched + Returns: + an integer position of the largest number in `seq` + """ + maxNum=seq[0] + maxPos=0 + for i in range(len(seq)): + if seq[i]>maxNum: + maxNum=seq[i] + maxPos=i + return maxPos + + +# def averageTry(target, promptText, failText, guess, repeats=2): +# # Provided to assist. If you use it, document it properly... :) +# # Runs multiple attempts at cracking the binary, returning the +# # success AND the average length of time each try took +# results=[] +# success=False +# for i in range(repeats): +# b=Binary(target) +# b.run() +# result=b.timedAttempt(promptText,guess, failText) +# success=result[0] +# results.append(result[1]) +# return (success,sum(results)/len(results)) + +def breakBinary(target, promptText, failText): + + + #Your code here + # Suggested algorithm: + + #1. Use an accumulator for the current guess + #2. in a loop, try the current guess plus each letter of the alphabest and see which one takes longest + #3. If it is the correct password, end + #4. If not, add the current best letter to the guess and repeat... + pass + + + +if __name__=="__main__": + + + # Create a simple menu system to pick the binary we want to force + targets=[] + targets.append(["targets/advanced1","Password:", "Password Incorrect"]) + targets.append(["targets/advanced2","Password:", "Password Incorrect"]) + targets.append(["targets/advanced3","Password:", "Password Incorrect"]) + + print("Intermediate Binary Breaker") + print("Which binary do you want to brute force?") + + for c in range(len(targets)): + print(f"{c}: {targets[c][0]}") + + selection=int(input("Enter the number of the binary to be forced: ")) + + if 0 <= selection < len(targets): + target=targets[selection] + breakBinary(target[0],target[1],target[2]) + else: + print("Invalid selection") diff --git a/src/brutus.py b/src/brutus.py index ad64136..d68d46a 100644 --- a/src/brutus.py +++ b/src/brutus.py @@ -4,6 +4,7 @@ Brutus provides a simple interface for you to run a binary or script and test a """ import pexpect +import time class Binary: """ Represents a binary file for cracking and allows it to be run with given input and a test for correct/incorrect password """ @@ -54,3 +55,24 @@ class Binary: return False except pexpect.exceptions.EOF: return True + + + def timedAttempt(self,prompt,data,fail): + """ Make a guess at a password, when the expected prompt is found + Args: + prompt: a string to idenitfy in the output that signifies WHEN to make the attempt + data: a string to send as the password guess + fail: the text expected on a failed attempt + Returns: + a tuple in which the first item is: + + - True: If the failure text *IS NOT* found in the output after the attempt + + - False: If the failure text *IS* found in the output after the attempt + + and the second item is the number of fractional seconds the guess took to make + """ + t1=time.perf_counter() + result=self.attempt(prompt,data,fail) + t2=time.perf_counter() + return (result,t2-t1) diff --git a/test/test_maxPos.py b/test/test_maxPos.py new file mode 100644 index 0000000..34d588e --- /dev/null +++ b/test/test_maxPos.py @@ -0,0 +1,14 @@ +import pytest +import sys +sys.path.append("./src/") + + +#You will need to write tests for your own functions, or change tests for ones you modify + +from brute_advanced import maxPos + + +def test_maxPos(): + assert maxPos([1,2,3])==2 + assert maxPos([1])==0 + assert maxPos([1,-10])==0