Skip to content
Permalink
Browse files
Initial import of "brutus" library.
  • Loading branch information
csx239 committed Oct 7, 2020
1 parent 7e4a6c1 commit 058239c12b9328efbd7ce7ac8a7fbee4fb0c9223
Showing 1 changed file with 45 additions and 0 deletions.
@@ -0,0 +1,45 @@
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

0 comments on commit 058239c

Please sign in to comment.