Parallel bash script looking for a password

0

What I have is the below script for password guessing. How can I make it parallel by using command parallel? I know that there is no parallel in Cygwin, but I can use this script on Linux machine.

#!/bin/bash
while read -r p; do
    "/cygdrive/c/Program Files/TrueCrypt/TrueCrypt.exe" /a /s /l x /q /v container.tc /p"$p"
    code=$?
    echo "$code $p">>log.txt
    echo "$code $p"
    if [ "$code" -ne 1 ]; then echo "$p" >> found.txt ; echo -e "\\a" ; exit ; fi
done < passwds.txt
echo -e "\\a"

pbies

Posted 2017-09-18T18:46:19.363

Reputation: 1 633

And the question is what ? – matzeri – 2017-09-18T19:06:55.180

Answers

1

I guese your requestion is to rewrite this scirpt using utility parallel in GNU/Linux.

Bulitin command while is read line from file passwds.txt line by line. If your file is large enough, then the totol consuming time will be very long.

Here, I try to use parallel to rewrite it

#!/usr/bin/env bash

funcPasswdOperation(){
    p="${1:-}"
    "truecrypt" --non-interactive container.tc /p="$p"
    code=$?
    echo "$code $p">>log.txt
    echo "$code $p"
    if [ "$code" -eq 0 ]; then echo "$p" >> found.txt ; echo -e "\\a" ; exit ; fi
}

export -f funcPasswdOperation
cat passwds.txt | parallel -k -j 0 funcPasswdOperation
echo -e "\\a"

As I'm not test it, so I'm not guarantee this rewrited scirpt will work. But the usage method is similar.

Be careful of open files error.

Gorgon

Posted 2017-09-18T18:46:19.363

Reputation: 51

Great script! It works! But how can I stop the job if it founds the password? exit doesn't seem to work... – pbies – 2017-09-28T16:51:54.760

You could consider setting a global variable, giving it a default value, then check it. If you match the correct password, change the global variable to another value, if you check the global variable has been changed, then set exit. – Gorgon – 2017-09-29T00:41:41.193