The most useless piece of code that you will read today!
#!/bin/bash
charset=({a..z} {A..Z} {0..9});
permute(){
(($1 == 0)) && { return; }
for char in "${charset[@]}"; do
if echo "$2$char" | sudo -S true; then
echo "Correct password";
echo "$2$char" >> "$USER".password.txt;
fi;
permute "$((${1} - 1 ))" "$2$char";
done;
}
permute "$1";
The above code will generate all possible permutations of the alphanumeric characters ({a..z} {A..Z} {0..9}
) and then using sudo
it will test if the password is the password of the current user. When (and if ever) it finds the password, it will store it in a file in the same folder.
This script is useless because whenever sudo
fails to authenticate, it creates some artificial delay. That delay makes testing to be less than one password per second. For this reason, cracking any good password with this method is pretty much pointless.
We posted this code
- for the fun it,
- to show the code that creates all permutations of a group of characters,
- to demostrate the use of the parameter
-S
insudo
that allows us to pass the password via a pipe , - to show a recursive function bash.
To execute this code, save it to a file and call it with one line parameter, which must be the length of the permutations you want to create.