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/brutus.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 lines (42 sloc)
1.72 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
import pexpect | |
class Binary: | |
""" Represents a binary file for cracking and allows it to be run with given input and a test for correct/incorrect password """ | |
def __init__(self,path,options=[]): | |
""" Initialises the binary | |
Args: | |
path: the absolute or relative path of the binary | |
options: an option list of options that are to be given to the binary on execution | |
""" | |
self.path=path | |
self.options=options | |
self.proc=None | |
self.queue=[] | |
def run(self): | |
""" Begins executing the binary. Returns as soon as it has been launched. """ | |
argv=[self.path]+self.options | |
self.proc=child = pexpect.spawn(" ".join(argv)) | |
def read(self): | |
""" Reads data from the standard output of the binary. | |
Returns: | |
None: if there is no data | |
A String: containing the next line of output if available.""" | |
if self.proc.eof(): | |
return None | |
return self.proc.readline() | |
def attempt(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: | |
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 | |
""" | |
self.proc.expect(prompt) | |
self.proc.send(data+"\n") | |
try: | |
self.proc.expect(fail, timeout=2) | |
return False | |
except pexpect.exceptions.EOF: | |
return True |