Skip to content

Instantly share code, notes, and snippets.

@superkojiman
Last active October 29, 2024 17:23
Show Gist options
  • Save superkojiman/11076951 to your computer and use it in GitHub Desktop.
Save superkojiman/11076951 to your computer and use it in GitHub Desktop.
Creating a user name list for brute force attacks.
#!/usr/bin/env python3
'''
NameMash by superkojiman
Generate a list of possible usernames from a person's first and last name.
https://blog.techorganic.com/2011/07/17/creating-a-user-name-list-for-brute-force-attacks/
'''
import sys
import os.path
if __name__ == '__main__':
if len(sys.argv) != 2:
print(f'usage: {sys.argv[0]} names.txt')
sys.exit(0)
if not os.path.exists(sys.argv[1]):
print(f'{sys.argv[1]} not found')
sys.exit(0)
with open(sys.argv[1]) as f:
for line in enumerate(f):
# remove anything in the name that aren't letters or spaces
name = ''.join([c for c in line[1] if c == ' ' or c.isalpha()])
tokens = name.lower().split()
if len(tokens) < 1:
# skip empty lines
continue
# assume tokens[0] is the first name
fname = tokens[0]
# remaining elements in tokens[] must be the last name
lname = ''
if len(tokens) == 2:
# assume traditional first and last name
# e.g. John Doe
lname = tokens[-1]
elif len(tokens) > 2:
# assume multi-barrelled surname
# e.g. Jane van Doe
# remove the first name
del tokens[0]
# combine the multi-barrelled surname
lname = ''.join([s for s in tokens])
# create possible usernames
print(fname + lname) # johndoe
print(lname + fname) # doejohn
print(fname + '.' + lname) # john.doe
print(lname + '.' + fname) # doe.john
print(lname + fname[0]) # doej
print(fname[0] + lname) # jdoe
print(lname[0] + fname) # djoe
print(fname[0] + '.' + lname) # j.doe
print(lname[0] + '.' + fname) # d.john
print(fname) # john
print(lname) # joe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment