Useful Code

Crack a Program Input

from pwn import *

def crack(password):
	binary = process("./crackme")
	binary.sendline(password)
	incorrect = False
	print("Trying " , password)
	while not incorrect:
		data = binary.recv(1024)
		incorrect = b'incorrect' in data
	binary.close()
f = open("rockyou.txt", 'rb')
lines = f.readlines()
for line in lines:
	crack(line.strip())

Crack a Zip

import zipfile
from tqdm import tqdm

wordlist = "rockyou.txt"
zip_file = "file.zip"

zip_file = zipfile.ZipFile(zip_file)
n_words = len(list(open(wordlist, "rb")))
print("Total passwords to test:", n_words)

with open(wordlist, "rb") as wordlist:
    for word in tqdm(wordlist, total=n_words, unit="word"):
        try:
            zip_file.extractall(pwd=word.strip())
        except:
            continue
        else:
            print("[+] Password found:", word.decode().strip())
            exit(0)
print("[!] Password not found, try other wordlist.")

Rest of code can be found in the repo -

Last updated