Skip to content

Instantly share code, notes, and snippets.

@ghost-ng
Last active June 24, 2019 04:20
Show Gist options
  • Save ghost-ng/ed4c5291d8e93f44cfa55d33e0e331f5 to your computer and use it in GitHub Desktop.
Save ghost-ng/ed4c5291d8e93f44cfa55d33e0e331f5 to your computer and use it in GitHub Desktop.
from itertools import permutations
from itertools import product
from sys import exit
from time import sleep
import os
result = os.system('color') ## Allows the script to use colors
GREEN = '\033[92m'
RED = '\033[31m'
YELLOW = '\033[93m'
RSTCOLORS = '\033[0m'
save_filename = ""
wordlist_filename = ""
exit_prgm_flag = False
restart_flag = True
digit_placeholders = 0
digit_location = ''
def file_checks(file):
exists = os.path.isfile(file) # initial check
msg = (RED + "[!] Unable to find file, try again: " + RSTCOLORS)
while exists is False:
file = input(msg)
exists = os.path.isfile(file)
filename, file_extension = os.path.splitext(file)
return file, filename, file_extension
def help_descriptions(item):
help = {
'rotate':
'''This method will rotate the characters in your word an entire rotation.
Example:
test -> estt stte ttes test
Recommended Use Case: on a list of keyboard walks
''',
'scramble':
'''This method will output all permutations of each word in the wordlist.
Example:
test -> word wodr wrod wrdo...
Recommended Use Case: on a list of keyboard walks
''',
'capitalize':
'''This method will output all permutations of each capitalized letter.
Example:
test -> TeST TeSt TesT Test
Recommended Use Case: on a list of keyboard walks
''',
'add-integers':
'''This method will add integers before or after (or both).
Example:
test -> 1test 2test 3test 4test
Recommended Use Case: on a list of passwords you expect to be re-used or versioned
''',
'add-dates':
'''This method will add short and long years; will be added before and after (not both together)
Example:
test -> 1999test 99test test1999 test99
'''
,
'all': '''This option will run all methods in the following order: d i c r s'''
}
print(help[item])
def prompt():
global exit_prgm_flag
menu = {
'r': 'rotate characters',
's': 'scramble',
'c': 'capitalize',
'i': 'add integers to string',
'd': 'add dates to string',
'all': 'all'
}
help = '''
List of String Mangling Algorithms:
String Manipulations:
(r)otate
(s)cramble
(c)apitalize
Add New Words:
add-(i)ntegers
add-(d)ates
Perform all methods: all
help or ? to see this again
help [module]
example: help add-integers
exit to exit
'''
banner_info = '''
***************************************
** Choose Your Fate (order matters)**
** Example: i,c,r,s **
***************************************
'''
# print(command_list)
print(banner_info)
response = input("mangler>> ")
if 'help' in response or '?' in response:
if len(response.split(" ")) == 2:
help_descriptions(response.split(" ")[1])
else:
clear_screen()
print(help)
elif 'exit' in response:
# print("Found exit command")
# input()
exit_prgm_flag = True
clear_screen()
else:
selection_menu = ""
if 'all' in response:
response_lst = ['d','i','c','r','s']
else:
response_lst = response.split(',')
for item in response_lst:
try:
selection_menu = selection_menu + menu[item] + "\n"
sleep(.6)
except KeyError:
print("[-] Option '{}' does not exist".format(item))
return
msg = (YELLOW + "[*] You chose:\n{}\n{}\n{}" + RSTCOLORS).format(response_lst,selection_menu,wordlist_filename)
print(msg)
temp = input("[?] Is this OK? (Y/N)")
if temp.upper() == "Y":
run(save_filename, wordlist_filename, response_lst)
remove_duplicates(save_filename)
def run(save_filename, filename, response_lst):
global restart_flag
new_list = []
with open(save_filename, 'w', encoding='utf-8') as save_file:
#with tqdm.tqdm(os.path.getsize(filename)) as pbar: #<----pbar
with open(filename, 'r', encoding='utf-8') as wordlist:
#for word in tqdm(wordlist):
for word in wordlist:
#pbar.update(len(word)) #<----pbar
word = remove_special_chars(word)
for choice in response_lst:
if choice == 'i':
new_list = add_int_ctl([word])
#print(GREEN + "[+] Adding Integers - Complete" + RSTCOLORS)
if choice == 'r':
new_list = rotate_characters([word])
#print(GREEN + "[+] Rotating Characters - Complete" + RSTCOLORS)
if choice == 's':
new_list = scramble_words([word])
#print(GREEN + "[+] Scrambling Words - Complete" + RSTCOLORS)
if choice == 'c':
new_list = capitalize([word])
#print(GREEN + "[+] Capitalizing strings - Complete" + RSTCOLORS)
if choice == 'd':
new_list = add_dates([word])
#print(GREEN + "[+] Adding Dates - Complete" + RSTCOLORS)
write_to_file(save_file, new_list)
print(GREEN + "[+] Mangling Complete..." + RSTCOLORS)
restart_flag = True
def remove_duplicates(tmp_file):
lines_seen = set() # holds lines already seen
#save_file = save_filename.replace(".tmp",".txt")
save_file = input("[?] Save File Name: ")
with open(tmp_file,'r',encoding='utf-8') as input_file:
with open(save_file,'w',encoding='utf-8') as output_file:
for line in input_file:
if line not in lines_seen:
output_file.write(line)
lines_seen.add(line)
os.remove(save_filename)
def remove_special_chars(word):
word = word.strip()
word = word.rstrip()
return word
def write_to_file(file, lst):
for word in lst:
file.write(word.rstrip().strip() + "\n")
def clear_screen():
os.system('cls' if os.name == 'nt' else 'clear')
def add_int_ctl(lst):
'''
:param lst: input wordlist
:return: new wordlist
'''
global digit_location
global digit_placeholders
new_lst = []
if digit_placeholders == 0:
digits = input("[?] How many digit placeholders to add: ")
digit_placeholders = int(digits)
print("--> a - append")
print("--> p - prepend")
print("--> b - both")
loc = input("[?] ")
digit_location = loc
for cols in range(1, digit_placeholders + 1):
temp_lst = add_int(lst,cols,digit_location)
#print(temp_lst)
new_lst = temp_lst + new_lst
temp = dict.fromkeys(new_lst)
new_lst = list(temp)
return new_lst
#STRING ADDITIONS:
#concats numbers to the string (before, after, and both)
def add_int(lst,digits,loc='b'):
'''
:param lst: old wordlist
:param cols: how many digits to pre/append
:param loc: (a)ppend OR (p)repend or (b)oth
:return: new wordlist
'''
new_words = []
new_word_list = []
number_list = []
#number_list = list(product(range(10), repeat=cols))
for d in range(0, digits + 1):
number_list = number_list + list(product(range(10), repeat=d))
for word in lst:
for t in number_list:
num = ''.join(str(x) for x in t)
if loc == 'p':
new_word = num + word
new_word_list.append(new_word)
elif loc == 'a':
new_word = word + num
new_word_list.append(new_word)
else:
new_word = word + num
new_word_list.append(new_word)
new_word = num + word
new_word_list.append(new_word)
return new_word_list
#
# number_list = list(range(0,10))
#
# for word in lst:
# word = remove_special_chars(word)
# for number in number_list:
# number = str(number)
# #numbers = ''.join(str(x) for x in item)
# if loc == 'p':
# new_words.append(number + word)
# elif loc == 'a':
# new_words.append(word + number)
# else:
# new_words.append(word + number)
# new_words.append(number + word)
# new_words.append(number + word + number)
# return new_words + lst
#STRING MANIPULATIONS:
def capitalize(lst):
new_list = []
for word in lst:
word = remove_special_chars(word)
temp = map(''.join, product(*(sorted(set((c.upper(), c.lower()))) for c in word)))
new_list = new_list + list(temp)
return new_list
#Generate all permutations of words in a list
#Best if used against a keyboard-walk list
def scramble_words(lst):
new_list = []
for word in lst:
word = remove_special_chars(word)
new_list = new_list + list(map(''.join, permutations(word)))
return new_list
def rotate_characters(lst):
new_lst = []
# slice string in two parts for left and right
for word in lst:
word = remove_special_chars(word)
for d in range(1,len(word)+1):
Lfirst = word[0: d]
Lsecond = word[d:]
new_lst.append(Lsecond + Lfirst)
return new_lst
def add_dates(lst):
start_date = 1930
end_date = 2019
new_list = []
for word in lst:
word = remove_special_chars(word)
for year in range(start_date,end_date+1):
for d in range(0, len(word)):
Rsplit = word[d:len(word)]
Lsplit = word[0:d]
new_list.append(Lsplit + str(year) + Rsplit)
new_list.append(Lsplit + str(year)[2:] + Rsplit)
new_list = new_list + [word + str(year),word + str(year)[2:]] + lst
return new_list
def main():
global save_filename
global wordlist_filename
global restart_flag
global digit_placeholders
global digit_location
banner_art = '''
.---.
__ __ ___ | | __.....__ _..._
| |/ `.' `. | | .--./) .-'' '. .' '.
| .-. .-. '| |.-,.--. /.''\\ / .-''"'-. `. . .-. .
__ | | | | | || || .-. || | | |/ /________\ \| ' ' |
.:--.'. | | | | | || || | | | \`-' / | || | | |
/ | \ || | | | | || || | | | /("'` \ .-------------'| | | |
`" __ | || | | | | || || | '- \ '---. \ '-.____...---.| | | |
.'.''| ||__| |__| |__|| || | /'""'.\ `. .' | | | |
/ / | |_ '---'| | || || `''-...... -' | | | |
\ \._,\ '/ |_| \'. __// | | | |
`--' `" `'---' '--' '--'
'''
print(banner_art)
while exit_prgm_flag is False:
if restart_flag is True:
restart_flag = False
filename = input("[?] File path to your wordlist:")
wordlist_filename = filename.replace('"', '')
file, name, file_extension = file_checks(filename)
save_filename = file + "_mangled.tmp"
clear_screen()
prompt()
input("[*] Press enter to run again...")
digit_placeholders = 0
digit_location = ''
clear_screen()
print("Exiting...")
exit()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment