1

Just for fun I made a very simple Python program:

var = "bello"
pas = raw_input("insert password\n")
if(pas==var):
    print("\naccess granted\n")
    print("\ncool information")
else:
    print("\naccess denied")

Now I tried to brute force access using crunch, with the shell on ubuntu terminal:

crunch 1 5 | python pex.py

pex.py is the name of the program. But it doesn't work, I suspect that the execution of the program does not iterate, but i have no idea how to make this brute force attack work. Can you help me? Better with a complete explaination.

4
  • the question is: if i found myself in front of a program like the one i show, how can i bruteforce the password control? Commented Jun 18, 2018 at 12:37
  • crunch output a list of words, you have to iterate its output using bash and for each iteration run your python script. superuser.com/questions/284187/… Commented Jun 18, 2018 at 12:43
  • 1
    this is actually a bash question by the way. the python has not to be edited. Commented Jun 18, 2018 at 12:44
  • ok, and what is the bash code, in this case, to to iterate its output and for each iteration run pex.py? Commented Jun 18, 2018 at 12:57

2 Answers 2

1

Instead of taking raw_input, get the arguments passed when the program is called with sys.argv.

pas = argv[1]

Then, when you call python pex.py <password>, pas will get set to <password>.

Note

If the password is multiple words, this won't work. You'll need to join the contents of sys.argv (excluding the 0th element, that's the program name) with ' '.join().

pas = ' '.join(argv[1:])
Sign up to request clarification or add additional context in comments.

2 Comments

Python has not to be edited. The python is a bogus example. OP intent is to bruteforce a program. You can't edit the program to make it custom bruteforce-able. The goal is rather to find a way to feed the single password and iterate.
yes, i prefer you to not edit my program to make it more esely brutforceable, it's a bit like cheating
0

First output crunch to file. This has the side benefit you can actually check what crunch has generated. You might however skip the file.

crunch 1 5 >> pas.txt

Load the file into environment array (BASH 4 example)

readarray pas_a < ./pas.txt

Execute once per password

   for pas in "${pas_a[@]}"
   do
       ./python pex.py "$pas" &
   done < ./pas.txt

Remove the & to make it sequential rather than parallel.

Clean the array from environment if you like.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.