Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
brute_campbell/src/brute_basic.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
72 lines (50 sloc)
2.36 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
from brutus import Binary | |
# This is a starting-point for your project | |
# Most of the work is done for the basic task | |
# Intermediate will require reading from a dictionary file and creating guesses based on the contents | |
# For the advanced task, see the supporting module "brute_time" | |
def breakBinary(target, promptText, failText): | |
"""" Break into the given target binary. | |
Assumes "basic" level binary, with PIN codes of 000-999 | |
Args: | |
target: path to the binary. e.g. "./bins/basic1" | |
promptText: text to look for in the output that signals a password is required. e.g. "Password:" | |
failText: text that indicates an attempt failed. e.g. "Password Incorrect" | |
Returns: | |
None: if no successful attempt was made | |
string: a successful password""" | |
#Here, the guesses are listed explicitly. We *could* write out | |
#1000 guesses, but the point is to use the computer to do the | |
#brute force work, not our fingers | |
#For the basic task, the only functionality you need is to replace | |
#the line below with code that can generate all the potential | |
#guesses | |
guesses=["000","001","002","003","004"] | |
for g in guesses: | |
#The actual attempt | |
b=Binary(target) | |
b.run() | |
success=b.attempt(promptText,g, failText) | |
if success: | |
print(f"The Guess '{g}' appears to be correct") | |
return g #Return the answer. No need to "break" because the return exits the function | |
else: | |
print(f"guess: {g} - Password incorrect!") | |
return None #If we get here, it means we didn't return earlier in the loop with a successful guess | |
if __name__=="__main__": | |
# Create a simple menu system to pick the binary we want to force | |
targets=[] | |
targets.append(["targets/basic1","Password:", "Password Incorrect"]) | |
targets.append(["targets/basic2","PW:", "ACCESS DENIED"]) | |
targets.append(["targets/basic3","Got the PIN?", "NO"]) | |
print("Basic 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") |