How to Generate Word-Lists with Python for Dictionary Attacks « Null Byte :: WonderHowTo

As perAlex's request, I am posting about generating word-lists in Python.However, this is my FIRST attempt with Python, so please provide me with critiques and any and all comments. I really want to know what you think as there was a little bump here and there seeing as I am transitioning from C#.Why the Program?Well, let's just run through a simple scenario: you're about to hack a vulnerable login page, but you think that brute-force is going to take ages (in fact, there's a decent chance it will), so why not try out a dictionary attack first? Because it's faster.[Please check my math here. I have not slept in the last 30 hours. I am not responsible for nonsense hereafter!]The English alphabet is 26 characters in length, and a 5 character password utilising brute force is 26^5, assuming it is not uppercase and has no special characters. 26^5 = 11881376 combinations! And that's the easy tier. Try a full dictionary—916132832 combinations (includes just upper, lower case and numbers).In these instances, you might want to try a dictionary attack. Now assuming a user has a password such as "thistle", a normal dictionary will suffice, but what if a password is "xZya6"?Well this is the program for you!RequirementsPythonStep1Beginning of Your Code#! C:\python27import string, randomThe above two lines are the beginning of our code.Since I am working on windowzer, my first line points to where I installed my Python. For linux users, change it to#!/usr/bin/pythonThe import declaration just tells the program to import the string handling library and a library to handle random chars.Step2The Meat & BonesNow, if we think about it, we want to be able to do the following:Tell the program how short each word should be.Tell the program how long each word should be.Tell the program how many words to generate.So enter these lines:minimum=input('Please enter the minimum length of any give word to be generated: ')maximum=input('Please enter the maximum length of any give word to be generated: ')wmaximum=input('Please enter the max number of words to be generate in the dictionary: ')Now decide on what kind of alphabet you will use—I chose the below:alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYX0123456789'Replace above with -alphabet = string.letters[0:52] + string.digits + string.punctuation..for runtime-generated alphabet in full ascii (no special symbols such as ¶)Next, declare the placeholder for our words.string=''Now, we tell Python to open a empty text file in write mode ("w"). (Linux users, point it your respective directory, or just write the file name if the file is next to your PY script)FILE = open("wl.txt","w")Now we write a loop which will range from 0 to the maximum number of words you defined, and generate words that hold random characters from the alphabet we defined earlier, in random order at variable length (assuming your min/max values were not identical on imput).for count in xrange(0,wmaximum):for x in random.sample(alphabet,random.randint(minimum,maximum)):string+=xNow we tell Python to write the strings (words) to the file we pointed the program to, by using '\n' to tell Python to separate each word in a new line.FILE.write(string+'\n')And the last functions are just: (1) Clear the string, (2) Close the file after editing—very important as changes might not register if it is not closed—and (3) prints the word "Done!" after finishing.string=''FILE.close()print 'DONE!'And that's it! Give it a go!Source CodeDownload it here!Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedHow To:Make a Locked File Cracker with PythonDeath Sentence for SCRABBLE:The Racism Debate Continues...How to Train Your Python:Part 11, Tuples and DictionariesHack Like a Pro:Python Scripting for the Aspiring Hacker, Part 3 (Building an FTP Password Cracker)News:The Ultimate SCRABBLE Word List ResourceHow To:Create Custom Wordlists for Password Cracking Using the MentalistHow To:Brute-Force SSH, FTP, VNC & More with BruteDumHack Like a Pro:How to Crack Passwords, Part 4 (Creating a Custom Wordlist with Crunch)How To:Brute-Force Nearly Any Website Login with HatchHow To:Add Foreign Language Dictionaries to Your iPhone to Look Up Definitions FasterHack Like a Pro:How to Crack Passwords, Part 1 (Principles & Technologies)How To:Fully Customize Your Samsung Galaxy S3's Dictionary Using Old Tweets, Statuses, Emails, & TextsHow To:Personalize Your Android's Dictionary with Words from Your Emails, Texts, & Social MediaScrabble Challenge #5:Put Your 2-Letter Word Skills to the TestHow To:Use the Hidden Thesaurus on Your iPhone in iOS 12 for Fast Synonym Searches in 'Look Up'Tutorial:Password Profiling with CUPPHacking macOS:How to Create a Fake PDF Trojan with AppleScript, Part 1 (Creating the Stager)How to Train Your Python:Part 13, Advanced Lists, Slicing, and ComprehensionNews:Advanced Cracking Techniques, Part 1: Custom DictionariesWeekend Homework:How to Become a Null Byte ContributorNews:How Controversy Changed SCRABBLEGoodnight Byte:Coding a Web-Based Password Cracker in PythonSCRABBLE Evolution:From Boards & Brew to Pockets & Programs to Cheats & CheatingNews:Scrabble Dumbs Down Its Game with 3,000 New WordsNews:Possible New SCRABBLE Words?How To:How Hackers Steal Your Internet & How to Defend Against ItNews Alert:Scrabble Makes You SmarterRevealed:Hundreds of words to avoid using onlineHow To:Play and Win Bananagrams – Scrabble's Addictive and Fast-Paced CousinNews:Advanced Cracking Techniques, Part 2: Intelligent BruteforcingHow To:Score Big with Simple 2-Letter Words in ScrabbleHow To:Hack Mac OS X Lion PasswordsScrabble Bingo of the Day:HOOSGOWNews:Obama supports drone attacksNews:A Step Back-"words" — SCRABBLE Trickster Hits UK StoresNews:SCRABBLE Now Allows Proper Nouns