Gianluca Peri
Gianluca Peri

Reputation: 13

How to pass multiple strings to a python program

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.

Upvotes: 1

Views: 311

Answers (2)

Attersson
Attersson

Reputation: 4866

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.

Upvotes: 0

jajaperson
jajaperson

Reputation: 558

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:])

Upvotes: 1

Related Questions