├── .gitignore ├── README.md ├── ShoppingList.txt ├── end ├── CH01 │ └── README.md ├── CH02 │ ├── HelloWorld.py │ ├── HelloWorld2.py │ ├── HelloWorld3.py │ ├── README.md │ └── SimpleCalculator.py ├── CH03 │ ├── Conditionals.py │ ├── Funcy.py │ ├── Loopy.py │ ├── README.md │ ├── deleteme.py │ ├── pinger1.py │ ├── pinger2.py │ ├── pinger3.py │ └── pinger4.py ├── CH04 │ ├── README.md │ ├── ReadFile.py │ ├── ScannerExample.py │ ├── WriteFile.py │ ├── ips.txt │ ├── pinger5.py │ └── pinger6.py ├── CH05 │ ├── ASCIIgen.py │ ├── Base64.py │ ├── CryptExample.py │ ├── README.md │ └── Rot13.py ├── CH06 │ ├── CreateHash1.py │ ├── CreateHash2.py │ ├── README.md │ ├── bruteforceAttack.py │ ├── dictionaryAttack.py │ ├── passHasher.py │ ├── shadow │ ├── top10.txt │ └── top1000.txt ├── CH07 │ ├── Find404.py │ ├── FindClients.py │ ├── FindPotentialHacking.py │ ├── FindStatusCodes.py │ ├── README.md │ └── access.log ├── CH08 │ ├── HaveIBeenPwned.py │ ├── ListRepositories.py │ ├── PeopleInSpace1.py │ └── PeopleInSpace2.py ├── CH09 │ ├── CheckURL.py │ ├── ScanFile.py │ └── test.json ├── CH10 │ ├── README.md │ ├── flask_hello.py │ ├── flask_mvc_space │ │ ├── app.py │ │ ├── models.py │ │ ├── static │ │ │ └── styles.css │ │ └── templates │ │ │ ├── index.html │ │ │ └── result.html │ ├── geometry_managers.py │ ├── tkinter_button.py │ ├── tkinter_dadjokes.py │ ├── tkinter_hello.py │ ├── tkinter_label.py │ └── tkinter_peopleinspace.py └── CH11 │ ├── answer_questions.py │ └── create_image.py └── start ├── CH01 └── README.md ├── CH02 ├── HelloWorld.py ├── HelloWorld2.py ├── HelloWorld3.py ├── README.md └── SimpleCalculator.py ├── CH03 ├── Conditionals.py ├── Funcy.py ├── Loopy.py ├── README.md ├── deleteme.py ├── pinger1.py ├── pinger2.py ├── pinger3.py └── pinger4.py ├── CH04 ├── README.md ├── ReadFile.py ├── ScannerExample.py ├── WriteFile.py ├── ips.txt ├── pinger5.py └── pinger6.py ├── CH05 ├── ASCIIgen.py ├── Base64.py ├── CryptExample.py ├── README.md └── Rot13.py ├── CH06 ├── CreateHash1.py ├── CreateHash2.py ├── README.md ├── bruteforceAttack.py ├── dictionaryAttack.py ├── passHasher.py ├── shadow ├── top10.txt └── top1000.txt ├── CH07 ├── Find404.py ├── FindClients.py ├── FindPotentialHacking.py ├── FindStatusCodes.py ├── README.md └── access.log ├── CH08 ├── HaveIBeenPwned.py ├── ListRepositories.py ├── PeopleInSpace1.py └── PeopleInSpace2.py ├── CH09 ├── CheckURL.py ├── ScanFile.py └── test.json ├── CH10 ├── README.md ├── geometry_managers.py ├── tkinter_button.py ├── tkinter_dadjokes.py ├── tkinter_hello.py └── tkinter_peopleinspace.py └── CH11 ├── answer_questions.py └── create_image.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # Environments 30 | .env 31 | .venv 32 | env/ 33 | venv/ 34 | ENV/ 35 | env.bak/ 36 | venv.bak/ 37 | 38 | # PyInstaller 39 | # Usually these files are written by a python script from a template 40 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 41 | *.manifest 42 | *.spec 43 | 44 | # Installer logs 45 | pip-log.txt 46 | pip-delete-this-directory.txt 47 | 48 | # Unit test / coverage reports 49 | htmlcov/ 50 | .tox/ 51 | .nox/ 52 | .coverage 53 | .coverage.* 54 | .cache 55 | nosetests.xml 56 | coverage.xml 57 | *.cover 58 | *.py,cover 59 | .hypothesis/ 60 | .pytest_cache/ 61 | cover/ 62 | 63 | # Translations 64 | *.mo 65 | *.pot 66 | 67 | # Django stuff: 68 | *.log 69 | local_settings.py 70 | db.sqlite3 71 | db.sqlite3-journal 72 | 73 | # Flask stuff: 74 | instance/ 75 | .webassets-cache 76 | 77 | # Scrapy stuff: 78 | .scrapy 79 | 80 | # Sphinx documentation 81 | docs/_build/ 82 | 83 | # PyBuilder 84 | .pybuilder/ 85 | target/ 86 | 87 | # Jupyter Notebook 88 | .ipynb_checkpoints 89 | 90 | # IPython 91 | profile_default/ 92 | ipython_config.py 93 | 94 | # pyenv 95 | # For a library or package, you might want to ignore these files since the code is 96 | # intended to run in multiple environments; otherwise, check them in: 97 | # .python-version 98 | 99 | # pipenv 100 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 101 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 102 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 103 | # install all needed dependencies. 104 | #Pipfile.lock 105 | 106 | # poetry 107 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 108 | # This is especially recommended for binary packages to ensure reproducibility, and is more 109 | # commonly ignored for libraries. 110 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 111 | #poetry.lock 112 | 113 | # pdm 114 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 115 | #pdm.lock 116 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 117 | # in version control. 118 | # https://pdm.fming.dev/latest/usage/project/#working-with-version-control 119 | .pdm.toml 120 | .pdm-python 121 | .pdm-build/ 122 | 123 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 124 | __pypackages__/ 125 | 126 | # Celery stuff 127 | celerybeat-schedule 128 | celerybeat.pid 129 | 130 | # SageMath parsed files 131 | *.sage.py 132 | 133 | # Environments 134 | .env 135 | .venv 136 | env/ 137 | venv/ 138 | ENV/ 139 | env.bak/ 140 | venv.bak/ 141 | 142 | # Spyder project settings 143 | .spyderproject 144 | .spyproject 145 | 146 | # Rope project settings 147 | .ropeproject 148 | 149 | # mkdocs documentation 150 | /site 151 | 152 | # mypy 153 | .mypy_cache/ 154 | .dmypy.json 155 | dmypy.json 156 | 157 | # Pyre type checker 158 | .pyre/ 159 | 160 | # pytype static type analyzer 161 | .pytype/ 162 | 163 | # Cython debug symbols 164 | cython_debug/ 165 | 166 | # PyCharm 167 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 168 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 169 | # and can be added to the global gitignore or merged into this file. For a more nuclear 170 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 171 | #.idea/ 172 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PythonforCybersecurity 2 | Python for cybersecurity repo 3 | -------------------------------------------------------------------------------- /ShoppingList.txt: -------------------------------------------------------------------------------- 1 | Milk 2 | Break 3 | Bananas 4 | Eggs 5 | 6 | -------------------------------------------------------------------------------- /end/CH01/README.md: -------------------------------------------------------------------------------- 1 | # Intro to Linux environment 2 | Brief introduction to Raspberry Pi 3 | - Why it was invented 4 | - benefits of Linux 5 | - some simple commands + links to finding more 6 | 7 | # Workign with github 8 | Create GitHub Account 9 | Use `git clone` to download/sync to linux 10 | Commands to push/pull 11 | ``` 12 | git pull 13 | git add . 14 | git commit -m "comment here" 15 | git push 16 | ``` 17 | github publish script 18 | 19 | ## Optionally 20 | - using .gitignore 21 | - other ways to store passwords 22 | 23 | # Intro to python - no scripting, just talk about it 24 | Benefits of python 25 | Where python is used 26 | Interpreted vs compiled language 27 | -------------------------------------------------------------------------------- /end/CH02/HelloWorld.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple "Hello World" script in python 3 | # Created by Ed Goad, 2/3 4 | print("Hello World") -------------------------------------------------------------------------------- /end/CH02/HelloWorld2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple "Hello World" script in python with Inputs 3 | # Created by Ed Goad, 2/3 4 | 5 | your_name = input("What is your name? ") 6 | print("Hello {0}".format(your_name)) 7 | -------------------------------------------------------------------------------- /end/CH02/HelloWorld3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple "Hello World" script in python with Inputs 3 | # Created by Ed Goad, 2/3 4 | 5 | # Get users name 6 | your_name = input("What is your name? ") 7 | 8 | # String formatting and f-string 9 | print("Hello {0}".format(your_name)) 10 | print(f"Hello {your_name}") 11 | 12 | # String concatenation 13 | print("Hello " + your_name) 14 | 15 | # Multiple print arguments 16 | print("Hello", your_name) 17 | 18 | # Constructing new variables 19 | message = "Hello" + " " + your_name 20 | print(message) 21 | 22 | # Removing newline 23 | print("Hello ", end = "") 24 | print(your_name) 25 | 26 | # Old style formatting 27 | print("Hello %s" % your_name) 28 | 29 | # Joining text 30 | print(" ".join(["Hello", your_name])) 31 | -------------------------------------------------------------------------------- /end/CH02/README.md: -------------------------------------------------------------------------------- 1 | # Starting with python3 2 | - interactive python 3 | ``` 4 | python3 5 | 20 + 32 6 | 15 - 7 7 | 7 * 7 8 | 2 ** 8 9 | print("Hello There") 10 | ``` 11 | - variables: variable is a box, whats in it what you put there 12 | ``` 13 | message = "Hello There" 14 | print(message) 15 | n = 17 16 | pi = 3.1415926535 17 | print(n + pi) 18 | ``` 19 | - data types 20 | ``` 21 | type(message) 22 | type(n) 23 | type(pi) 24 | ``` 25 | # Starting with an IDE 26 | - Installing VSCode 27 | - Syncronizing with GitHub 28 | 29 | 30 | # creating first few scripts 31 | ### HelloWorld.py 32 | - Commit to Github 33 | - Running in IDE and command line 34 | 35 | ### HelloWorld2.py 36 | - Commit and run with simple input/print 37 | - Different ways to print the hello statement (add all then run) 38 | 39 | # Use IDE debugger 40 | - Using HelloWorld2.py 41 | - stop at first print statement and step through code -------------------------------------------------------------------------------- /end/CH02/SimpleCalculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple calculator to show math and conditionals 3 | # Created by Ed Goad, 2/3/2021 4 | 5 | # Get inputs first 6 | # Note we are casting the numbers as "float", we could also do "int" 7 | first_num = float(input("What is the first number: ")) 8 | activity = input("What activity? ( + - * / ) ") 9 | second_num = float(input("What is the second number: ")) 10 | 11 | # depending on the selected activity, perform an action 12 | if activity == "+": 13 | print(first_num + second_num) 14 | if activity == "-": 15 | print(first_num - second_num) 16 | if activity == "*": 17 | print(first_num * second_num) 18 | if activity == "/": 19 | print(first_num / second_num) 20 | -------------------------------------------------------------------------------- /end/CH03/Conditionals.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with conditionals 3 | #By Ed Goad 4 | # date: 2/3/2021 5 | 6 | # Suggestion - 7 | # add in <, ==, > one at a time 8 | # make each of them if statements initially 9 | # Change x and y values to test the various paths 10 | # eventually simplfy with if, elif, else 11 | 12 | def condTest(): 13 | x, y = 100, 10 14 | 15 | # First condition test, x is less than y 16 | if x < y: 17 | print("X is less than y") 18 | # Another conditional test, x is equal to y 19 | elif x == y: 20 | print("X is equal to y") 21 | # Last conditional test, x is greater than y 22 | else: 23 | print("X is greater than y") 24 | 25 | condTest() -------------------------------------------------------------------------------- /end/CH03/Funcy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with Functions 3 | #By Ed Goad 4 | # date: 2/3/2021 5 | 6 | # Suggestions - 7 | # build out 1 function at a time, from top down 8 | # comment out calls to functions that arent needed to keep the output clean 9 | # When finished, uncomment all calls, then put a breakpoint at first call 10 | # Use debugging to show difference between step-over, step-into, step-out 11 | 12 | # Basic function example 13 | def func1(): 14 | print("I am a function") 15 | 16 | # Function that adds numbers 17 | def addNums(val1, val2): 18 | print(val1 + val2) 19 | 20 | # Function that raises to exponent, default to squared 21 | def power(number, exp=2): 22 | print(number ** exp) 23 | 24 | # Fucntion that returns value 25 | def cube(x): 26 | return x**3 27 | 28 | func1() 29 | addNums(2, 5) 30 | power(5, 3) 31 | power(5) 32 | value = cube(5) 33 | print("The answer is {0}".format(value)) 34 | power(value, 5) 35 | 36 | 37 | print("The answer is {0}".format(cube(6))) -------------------------------------------------------------------------------- /end/CH03/Loopy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with Loops 3 | #By Ed Goad 4 | # date: 2/5/2021 5 | 6 | # Suggestion 7 | # build out 1 function at a time and walk through them with the debugger 8 | # not necessary to run all functions 9 | 10 | def forLoop(): 11 | for x in range(6): 12 | print(x) 13 | def whileLoop(): 14 | count = 0 15 | while (count < 6): 16 | print('The count is:', count) 17 | count = count + 1 18 | 19 | def basicLoopElse(): 20 | for x in range(6): 21 | print(x) 22 | else: 23 | print("Finally finished!") 24 | 25 | def loopArray(): 26 | fruits = ["apple", "banana", "cherry"] 27 | for x in fruits: 28 | print(x) 29 | def loopArray2(): 30 | for x in "banana": 31 | print(x) 32 | 33 | def loopBreak(): 34 | fruits = ["apple", "banana", "cherry"] 35 | for x in fruits: 36 | print(x) 37 | if x == "banana": 38 | break 39 | def loopBreak2(): 40 | fruits = ["apple", "banana", "cherry"] 41 | for x in fruits: 42 | if x == "banana": 43 | break 44 | print(x) 45 | def loopContinue(): 46 | fruits = ["apple", "banana", "cherry"] 47 | for x in fruits: 48 | if x == "banana": 49 | continue 50 | print(x) 51 | def loopPass(): 52 | for letter in 'Python': 53 | if letter == 'h': 54 | pass 55 | print('This is pass block') 56 | print('Current Letter :', letter) 57 | print("Good bye!") 58 | 59 | def nestedLoop(): 60 | adj = ["red", "big", "tasty"] 61 | fruits = ["apple", "banana", "cherry"] 62 | for x in adj: 63 | for y in fruits: 64 | print(x, y) 65 | 66 | #forLoop() 67 | #whileLoop() 68 | #basicLoopElse() 69 | #loopArray() 70 | #loopArray2() 71 | #loopBreak() 72 | #loopBreak2() 73 | #loopContinue() 74 | #loopPass() 75 | #nestedLoop() -------------------------------------------------------------------------------- /end/CH03/README.md: -------------------------------------------------------------------------------- 1 | # Its ok if this flows into next week 2 | 3 | # Ping 4 | Starting with simple ping script / interactive mode 5 | ``` 6 | import platform 7 | import os 8 | pingCMD = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 9 | os.system(pingCMD) 10 | ``` 11 | 12 | # Conditionals 13 | Show how conditionals work (if, elif, else) and evaluations (<>=) 14 | - Build out conditionals.py without function 1 evaluation at a time 15 | - Debug if necessary 16 | Add in conditionals to accomidate Windows or Linux 17 | - Try command on a Windows machine to see how it works differntly? 18 | - save as pinger1.py 19 | - use debugger to walk through it 20 | 21 | # Loops 22 | Show how loops work 23 | - simple FOR loop `for x in range(6):` 24 | - If time later, come back to more loop types 25 | Add in loop to loop through multiple IPs 26 | - start with simple print statement to show how to loop and how it will work 27 | - use debugger to walk through 28 | ``` 29 | startIP = "192.168.0." 30 | for x in range(254): 31 | ip = startIP + str(x + 1) 32 | print(ip) 33 | ``` 34 | - extend pinger1.py into pinger2.py 35 | - use debugger if necessary 36 | 37 | # Functions 38 | Show how functions work 39 | - reusable code 40 | - send input 41 | - receive output 42 | Move ping command into function 43 | - receive IP as input, return exit_code 44 | - save as pinger3.py 45 | - debug if necessary 46 | 47 | -------------------------------------------------------------------------------- /end/CH03/deleteme.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edgoadcom/PythonforCybersecurity/1c042e0a2d03ac25933c52ec26dfd5a786c34e84/end/CH03/deleteme.py -------------------------------------------------------------------------------- /end/CH03/pinger1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # First example of pinging from Python 3 | # By Ed Goad 4 | # 2/27/2021 5 | 6 | # import necessary Python modules 7 | import platform 8 | import os 9 | 10 | # Assign IP to ping to a variable 11 | ip = "127.0.0.1" 12 | # Build our ping command 13 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 14 | # Execute command and capture exit code 15 | exit_code = os.system(ping_cmd) 16 | # Print results to console 17 | print(exit_code) 18 | -------------------------------------------------------------------------------- /end/CH03/pinger2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Second example of pinging from Python 3 | # By Ed Goad 4 | # 2/27/2021 5 | 6 | # import necessary Python modules 7 | import platform 8 | import os 9 | 10 | # Assign IP to ping to a variable 11 | ip = "127.0.0.1" 12 | # Determine the currrent OS 13 | currrent_os = platform.system().lower() 14 | if currrent_os == "windows": 15 | # Build our ping command for Windows 16 | ping_cmd = f"ping -n 1 -w 2 {ip} > nul" 17 | else: 18 | # Build our ping command for other OSs 19 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 20 | 21 | # Execute command and capture exit code 22 | exit_code = os.system(ping_cmd) 23 | # Print results to console 24 | print(exit_code) 25 | -------------------------------------------------------------------------------- /end/CH03/pinger3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Third example of pinging from Python 3 | # By Ed Goad 4 | # 2/27/2021 5 | 6 | # import necessary Python modules 7 | import platform 8 | import os 9 | 10 | # Define the prefix to begin pinging 11 | ip_prefix = "192.168.0." 12 | # Determine the currrent OS 13 | currrent_os = platform.system().lower() 14 | # Loop from 0 - 254 15 | for final_octet in range(254): 16 | # Assign IP to ping to a variable 17 | # Adding 1 to final_octet because loop starts at 0 18 | ip = ip_prefix + str(final_octet + 1) 19 | if currrent_os == "windows": 20 | # Build our ping command for Windows 21 | ping_cmd = f"ping -n 1 -w 2 {ip} > nul" 22 | else: 23 | # Build our ping command for other OSs 24 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 25 | 26 | # Execute command and capture exit code 27 | exit_code = os.system(ping_cmd) 28 | # Print results to console only if successful 29 | if exit_code == 0: 30 | print("{0} is online".format(ip)) 31 | -------------------------------------------------------------------------------- /end/CH03/pinger4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fourth example of pinging from Python 3 | # By Ed Goad 4 | # 2/27/2021 5 | 6 | # import necessary Python modules 7 | import platform 8 | import os 9 | 10 | def ping_host(ip): 11 | # Determine the currrent OS 12 | currrent_os = platform.system().lower() 13 | if currrent_os == "windows": 14 | # Build our ping command for Windows 15 | ping_cmd = f"ping -n 1 -w 2 {ip} > nul" 16 | else: 17 | # Build our ping command for other OSs 18 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 19 | # Execute command and capture exit code 20 | exit_code = os.system(ping_cmd) 21 | return exit_code 22 | 23 | # Define the prefix to begin pinging 24 | ip_prefix = "192.168.0." 25 | 26 | # Loop from 0 - 254 27 | for final_octet in range(254): 28 | # Assign IP to ping to a variable 29 | # Adding 1 to final_octet because loop starts at 0 30 | ip = ip_prefix + str(final_octet + 1) 31 | 32 | # Call ping_host function and capture the return value 33 | exit_code = ping_host(ip) 34 | 35 | # Print results to console only if successful 36 | if exit_code == 0: 37 | print("{0} is online".format(ip)) 38 | -------------------------------------------------------------------------------- /end/CH04/README.md: -------------------------------------------------------------------------------- 1 | # Reading Files 2 | create a file named **testfile.txt** and show how to read it 3 | readFile.py 4 | 5 | Create a new file **ips.txt** and use it as input for loop (put whatever IPs desired) 6 | pinger4.py 7 | 8 | If time exists, put bad data in ips.txt and show how important it is to validate input 9 | 10 | # Writing Files 11 | show how to write a file 12 | writeFile.py 13 | 14 | Create function to write to a log 15 | pinger5.py 16 | Extend log by adding date/time 17 | - google how to get date/time for python -------------------------------------------------------------------------------- /end/CH04/ReadFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sample script that reads from a file 3 | # By Ed Goad 4 | # 12/12 5 | 6 | import os 7 | 8 | # Get current file directory 9 | script_path = os.path.abspath( __file__ ) 10 | script_dir = os.path.dirname( script_path ) 11 | # Build file path 12 | file_path = os.path.join(script_dir, "ips.txt") 13 | 14 | # Open file for reading 15 | ip_file = open(file_path, "r") 16 | 17 | # Read the contents of the file and print to screen 18 | ip_addresses = ip_file.read() 19 | print(ip_addresses) 20 | 21 | # Close the file 22 | ip_file.close() 23 | 24 | -------------------------------------------------------------------------------- /end/CH04/ScannerExample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Port scanner example 3 | # Use 'sudo apt -y install python3-pip' to install pip 4 | # Use 'sudo apt -y install nmap' to install nmap 5 | # Use 'pip3 install python-nmap' to install modules 6 | # By Ed Goad 7 | # 12/12 8 | 9 | # import necessary Python modules 10 | import nmap 11 | 12 | # Identify target address 13 | target_addresses = "192.168.0.0/24" 14 | 15 | # Identify the ports for the scan 16 | ports = "1-100" 17 | 18 | # Create the scanner object 19 | scanner = nmap.PortScanner() 20 | 21 | # Scan the network 22 | results = scanner.scan(target_addresses, ports, arguments="-T5") 23 | 24 | # Report results 25 | for target, host in results['scan'].items(): 26 | print(target) 27 | 28 | # If open ports are found, print the current state 29 | if 'tcp' in host: 30 | for port, status in host['tcp'].items(): 31 | print(f"\t{port} - {status['state']} ({status['name']})") 32 | -------------------------------------------------------------------------------- /end/CH04/WriteFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sample script that writes to a file 3 | # By Ed Goad 4 | # 12/12 5 | 6 | import os 7 | 8 | # Get current file directory 9 | script_path = os.path.abspath( __file__ ) 10 | script_dir = os.path.dirname( script_path ) 11 | # Build file path 12 | file_path = os.path.join(script_dir, "testfile.txt") 13 | 14 | # Open file for writing 15 | test_file = open(file_path, "w") 16 | 17 | # Write lines to the file 18 | test_file.write( "Hello World\n" ) 19 | test_file.write( "My name is Ed\n" ) 20 | test_file.write( "I like rubber ducks\n" ) 21 | 22 | # Close the file 23 | test_file.close() 24 | 25 | -------------------------------------------------------------------------------- /end/CH04/ips.txt: -------------------------------------------------------------------------------- 1 | 192.168.0.10 2 | 192.168.0.11 3 | 192.168.0.12 4 | 192.168.0.13 5 | 192.168.0.14 6 | 192.168.0.15 7 | 192.168.0.16 8 | 192.168.0.17 9 | 192.168.0.18 10 | 192.168.0.19 11 | 192.168.0.110 12 | 192.168.0.111 13 | 192.168.0.112 14 | 192.168.0.113 15 | 192.168.0.114 16 | 192.168.0.115 -------------------------------------------------------------------------------- /end/CH04/pinger5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fifth example of pinging from Python 3 | # Reading IPs from a file 4 | # By Ed Goad 5 | # 12/12 6 | 7 | # import necessary Python modules 8 | import platform 9 | import os 10 | 11 | def ping_host(ip): 12 | # Determine the current OS 13 | currrent_os = platform.system().lower() 14 | if currrent_os == "windows": 15 | # Build our ping command for Windows 16 | ping_cmd = f"ping -n 1 -w 2 {ip} > nul" 17 | else: 18 | # Build our ping command for other OSs 19 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 20 | # Execute command and capture exit code 21 | exit_code = os.system(ping_cmd) 22 | return exit_code 23 | 24 | def import_addresses(): 25 | # Get current file directory 26 | script_path = os.path.abspath( __file__ ) 27 | script_dir = os.path.dirname( script_path ) 28 | # Build file path 29 | file_path = os.path.join(script_dir, "ips.txt") 30 | 31 | # Create empty list object 32 | addresses = [] 33 | # Open file and read line-by-line 34 | f = open(file_path, "r") 35 | for line in f: 36 | # Use strip() to remove spaces and carriage returns 37 | line = line.strip() 38 | # Add the line to the addresses list object 39 | addresses.append(line) 40 | # Return the list object to the main body 41 | return addresses 42 | 43 | # read IPs from file 44 | ip_addresses = import_addresses() 45 | 46 | for ip in ip_addresses: 47 | # Call ping_host function and capture the return value 48 | exit_code = ping_host(ip) 49 | 50 | # Print results to console only if successful 51 | if exit_code == 0: 52 | print("{0} is online".format(ip)) 53 | -------------------------------------------------------------------------------- /end/CH04/pinger6.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sixth example of pinging from Python 3 | # Writing log messages to a file 4 | # By Ed Goad 5 | # 12/12 6 | 7 | # import necessary Python modules 8 | import platform 9 | import os 10 | from datetime import datetime 11 | 12 | def write_log(message): 13 | now = datetime.now() 14 | f = open("pinger.log", "a") 15 | f.write(f"{now}\t{message}\n") 16 | f.close() 17 | 18 | def ping_host(ip): 19 | # Determine the current OS 20 | currrent_os = platform.system().lower() 21 | if currrent_os == "windows": 22 | # Build our ping command for Windows 23 | ping_cmd = f"ping -n 1 -w 2 {ip} > nul" 24 | else: 25 | # Build our ping command for other OSs 26 | ping_cmd = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 27 | # Execute command and capture exit code 28 | exit_code = os.system(ping_cmd) 29 | return exit_code 30 | 31 | def import_addresses(): 32 | # Get current file directory 33 | script_path = os.path.abspath( __file__ ) 34 | script_dir = os.path.dirname( script_path ) 35 | # Build file path 36 | file_path = os.path.join(script_dir, "ips.txt") 37 | 38 | # Create empty list object 39 | addresses = [] 40 | # Open file and read line-by-line 41 | f = open(file_path, "r") 42 | for line in f: 43 | # Use strip() to remove spaces and carriage returns 44 | line = line.strip() 45 | # Add the line to the addresses list object 46 | addresses.append(line) 47 | # Return the list object to the main body 48 | return addresses 49 | 50 | # read IPs from file 51 | write_log("Reading IPs from ips.txt") 52 | ip_addresses = import_addresses() 53 | write_log("Imported {0} IPs".format(len(ip_addresses))) 54 | 55 | for ip in ip_addresses: 56 | # Call ping_host function and capture the return value 57 | exit_code = ping_host(ip) 58 | 59 | # Print results to console only if successful 60 | if exit_code == 0: 61 | write_log("{0} is online".format(ip)) 62 | print("{0} is online".format(ip)) 63 | else: 64 | write_log("{0} is offline".format(ip)) 65 | -------------------------------------------------------------------------------- /end/CH05/ASCIIgen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # ASCII generator 3 | # Uses chr() to create ASCII characters 4 | # By Ed Goad 5 | # 2/27/2021 6 | 7 | for i in range(127): 8 | print("{0}\t'{1}'".format(i,chr(i))) 9 | -------------------------------------------------------------------------------- /end/CH05/Base64.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that "encrypts"/"decrypts" text using base64 encoding 3 | # By Ed Goad 4 | # 2/5/2021 5 | 6 | # import necessary Python modules 7 | import base64 8 | 9 | def encode_data(plain_text): 10 | # Convert plain_text string to bytes 11 | plain_text = plain_text.encode() 12 | # Encode the plain_text 13 | cipher_text = base64.b64encode(plain_text) 14 | # Convert the encoded bytes back to string 15 | cipher_text = cipher_text.decode() 16 | return cipher_text 17 | 18 | def decode_data(cipher_text): 19 | # Decode the cipher_text 20 | plain_text = base64.b64decode(cipher_text) 21 | # Convert the decoded bytes to string 22 | plain_text = plain_text.decode() 23 | return plain_text 24 | 25 | # Prompt the user for method and message 26 | method = input("Do you wish to Encode or Decode (e/d)? ").lower() 27 | message = input("What is the message? ") 28 | 29 | # Using first letter in variable, 30 | # call the encode or decode function 31 | if method[0] == "e": 32 | print(encode_data(message)) 33 | elif method[0] == "d": 34 | print(decode_data(message)) 35 | else: 36 | # if method wasn't "e" or "d", print error message and quit 37 | print("Wrong method selected. Choose Encode or Decode") 38 | -------------------------------------------------------------------------------- /end/CH05/CryptExample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that encrypts/decrypts text using cryptography module 3 | # By Ed Goad 4 | # date: 12/12 5 | 6 | # May need 'pip3 install cryptography' or 7 | # 'pip3 install cryptography -U' prior to running 8 | 9 | # Import necessary Python modules 10 | from cryptography.fernet import Fernet 11 | 12 | # functions 13 | def fernet_create_key(): 14 | key = Fernet.generate_key() 15 | return key.decode() 16 | 17 | def fernet_encrypt(plain_text, key): 18 | # convert text and key to bytes object 19 | b_plain = plain_text.encode() 20 | b_key = key.encode() 21 | # Encrypt data 22 | b_cipher = Fernet(b_key).encrypt(b_plain) 23 | # convert back to string 24 | return b_cipher.decode() 25 | 26 | def fernet_decrypt(cipher_text, key): 27 | # convert to bytes object 28 | b_cipher = cipher_text.encode() 29 | b_key = key.encode() 30 | # Decrypt 31 | b_plain = Fernet(b_key).decrypt(b_cipher) 32 | # Convert to string 33 | return b_plain.decode() 34 | 35 | # prompt user for message and method 36 | method = input("Encrypt, Decrypt, or Key (e/d/k) ") 37 | message = input("Message: ") 38 | key = input("Key: ") 39 | method = method.lower()[0] 40 | 41 | # call the appropriate function 42 | if method == "e": 43 | cipher_text = fernet_encrypt(message, key) 44 | print(cipher_text) 45 | elif method == "d": 46 | plain_text = fernet_decrypt(message, key) 47 | print(plain_text) 48 | elif method == "k": 49 | key = fernet_create_key() 50 | print(key) 51 | else: 52 | print("Wrong selection, try again") -------------------------------------------------------------------------------- /end/CH05/README.md: -------------------------------------------------------------------------------- 1 | # Intro to cryptography 2 | 3 | # How cryptography *can work* - ROT13 4 | Introduce the idea of ROT13 5 | - **Hello World** --> **Uryyb Jbeyq** --> **Hello World** 6 | - https://en.wikipedia.org/wiki/ROT13 7 | - simple-ish to program because 13 + 13 = 26 --> 26 letters 8 | 9 | Introduct the ASCII table http://www.asciitable.com/ 10 | - highlight the fact that letters are numbers 11 | - Using interactive mode, show the **ord()** and **chr()** commands 12 | 13 | Start building **rot13.py** 14 | - Manually walk through converting **abc** --> **97 98 99** --> **110 111 112** --> **nop** 15 | - Use a for loop to access each letter individually. *Another way to use a for loop* 16 | - easy to start, but highlight issues as they occur 17 | - for ease, force everythign to be lower case 18 | - Figure out how to deal with non-letters (such as spaces) 19 | - make encrypt/decrypt process a function 20 | 21 | If time allows, use **base64.py** as example of more complex processing 22 | 23 | # WARNING - Dont create your own encryption scheme! 24 | rot13 is simple to understand, and can be easily expanded to rotx.py or encrypting files 25 | Unless you are a full time security researcher, dont "roll-your-own" encryption scheme, 26 | use the predefined encryption modules. What is hard for you, coudl be easy for someone else. 27 | 28 | The goal of cryptography is that the crypto process should be commonly known. What should 29 | be secret is the encryption keys. That way everyone can provide input on the best scheme 30 | to use, resulting in a better and more secure encryption process 31 | 32 | # Legit cryptography 33 | Highlight https://pypi.org/ as a repository of Python packages/libraris/dlls 34 | There are 2 programs, **pip** and **pip3**. In general pip3 is for Python3 35 | NOTE: For the cryptography library, you may need to use one of the following commands to install the cryptography module: 36 | ``` 37 | pip3 install cryptography 38 | ``` 39 | Fernet is a type of *symmetric cryptography* - same key to encrypt and decrypt 40 | Unlike ROT13, there are different processes to encrypt and decrypt 41 | 42 | ## start in interactive mode 43 | ### generate key 44 | ``` 45 | from cryptography.fernet import Fernet 46 | Fernet.generate_key() 47 | ``` 48 | Note the case sensitivity and the **b** before the output 49 | The **b** refers to bytes, this is easier for the computer to handle. 50 | Do a `print(type(key))` and `print(type(key.decode()))` to confirm 51 | to remove the **b**, we **decode** it 52 | ``` 53 | key = Fernet.generate_key() # store in a secure location 54 | print("Key:", key.decode()) 55 | ``` 56 | ### encrypt data 57 | ``` 58 | plainText = "Hello There" 59 | plainText = plainText.encode() 60 | cipherText = Fernet(key).encrypt(plainText) 61 | cipherText = cipherText.decode() 62 | print(cipherText) 63 | ``` 64 | ### decrypt data 65 | ``` 66 | cipherText = cipherText.encode() 67 | key = key.encode() 68 | plainText = Fernet(key).decrypt(cipherText) 69 | plainText = plainText.decode() 70 | ``` 71 | 72 | 73 | 74 | 75 | 76 | 77 | # Lots of encryption examples online 78 | https://cryptography.io/en/latest/fernet.html 79 | https://www.geeksforgeeks.org/fernet-symmetric-encryption-using-cryptography-module-in-python/ 80 | https://devqa.io/encrypt-decrypt-data-python/ 81 | https://www.programcreek.com/python/example/98805/cryptography.fernet.Fernet 82 | https://docs.python-guide.org/scenarios/crypto/ 83 | 84 | -------------------------------------------------------------------------------- /end/CH05/Rot13.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that encrypts/decrypts text using ROT13 3 | # By Ed Goad 4 | # date: 2/5/2021 5 | 6 | # Prompt for the source message 7 | source_message = input("What is the message to encrypt/decrypt? ") 8 | # Convert message to lower-case for simplicity 9 | source_message = source_message.lower() 10 | final_message = "" 11 | 12 | # Loop through each letter in the source message 13 | for letter in source_message: 14 | # Convert the letter to the ASCII equivalent 15 | ascii_num = ord(letter) 16 | # Check to see if an alphabetic (a-z) character, 17 | # if not, skip 18 | if ascii_num >= 97 and ascii_num <= 122: 19 | # Add 13 to ascii_num to "shift" it by 13 20 | new_ascii = ascii_num + 13 21 | # Confirm new character will be alphabetic 22 | if new_ascii > 122: 23 | # If not, wrap around 24 | new_ascii = new_ascii - 26 25 | final_message = final_message + chr(new_ascii) 26 | else: 27 | final_message = final_message + chr(ascii_num) 28 | 29 | # Print converted message 30 | print("Message has been converted:") 31 | print(final_message) -------------------------------------------------------------------------------- /end/CH06/CreateHash1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password 3 | # By Ed Goad 4 | # date: 11/1/2024 5 | 6 | # Import Python modules 7 | from passlib.hash import sha256_crypt 8 | from passlib.hash import sha512_crypt 9 | from passlib.hash import lmhash 10 | from passlib.hash import nthash 11 | from passlib.hash import md5_crypt 12 | 13 | #prompt user for plain-text password 14 | plain_password = input("What is the password? ") 15 | 16 | # Print out the hashes 17 | print("MD5 : {0}".format(md5_crypt.hash(plain_password))) 18 | print("SHA-256 : {0}".format(sha256_crypt.hash(plain_password))) 19 | print("SHA-512 : {0}".format(sha512_crypt.hash(plain_password))) 20 | print("LMhash : {0}".format(lmhash.hash(plain_password))) 21 | print("NThash : {0}".format(nthash.hash(plain_password))) -------------------------------------------------------------------------------- /end/CH06/CreateHash2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password with provided salt 3 | # By Ed Goad 4 | # date: 11/1/2024 5 | 6 | # Import Python modules 7 | from passlib.hash import sha256_crypt 8 | from passlib.hash import sha512_crypt 9 | 10 | # Prompt user for plain-text password 11 | plain_password = input("What is the password? ") 12 | salt = input("What is the salt? ") 13 | 14 | # Print out hashes 15 | print("SHA-256 : {0}".format( 16 | sha256_crypt.hash(plain_password, salt=salt)) 17 | ) 18 | print("SHA-512 : {0}".format( 19 | sha512_crypt.hash(plain_password, salt=salt)) 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /end/CH06/README.md: -------------------------------------------------------------------------------- 1 | # Hacking linux passwords 2 | Linux passwords are stored in the file /etc/shadow, which is only readable by root. This restriction is added because if you can read the passwords, you can hack the passwords. 3 | These arent the passwords, but hashes of the passwords. Hashing is similar to encryption, but is a one-way process and can't be unencrypted. This means the actual password cant be retrieved from the hash 4 | We can however **guess** at the contents, and then hash them to see if they match 5 | 6 | # Breakdown of /etc/shadow 7 | Sample line from /etc/shadow. Username **justincase**, password **Password01** 8 | `justincase:$6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.:18617:0:99999:7:::` 9 | 10 | The password hash is between 1st and 2nd colons (`$6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.` in the example above) 11 | The password hash is made up of: 12 | 1. the first few characters define the hashing algorithm: (`$6` in the example above) 13 | - $1=MD5 14 | - $2=Blowfish 15 | - $2a=eksblowfish 16 | - $5=SHA-256 17 | - $6=SHA-512 18 | 2. A SALT which is between the 2 dollar signs (`G.DTW7g9s5U7KYf5` in the example above) 19 | - Note: the SALT is random and is used to complicate the HASH 20 | - This ensures if 2 passwords are the same, the HASH is different 21 | 3. The hash of the salted password (`xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.`) 22 | 23 | # Creating password hashes 24 | Uses **crypt** module. NOTE: this is a Linux module and may not work on other operating systems. There are similar modules for Windows, search Google for the best option. 25 | Possibly start in interactive mode. Show without / with SALT 26 | ``` 27 | import crypt 28 | print(crypt.crypt("Password01") 29 | print(crypt.crypt("Password01", "$6$G.DTW7g9s5U7KYf5$") 30 | ``` 31 | Use **passHasher.py** to show different encryption methods (not all are available) 32 | Demonstrate how the SALT changes the HASH 33 | If same password and salt are used, resultant HASH is the same -- this is how passwords work 34 | 35 | # Guessing passwords 36 | Create script that prompts for: 37 | 1. Hashed password from /etc/shadow 38 | 2. The SALT to use 39 | 3. Plaintext password 40 | 41 | Create a function called **testPass** that hashes the plaintext password with the salt and compares with the hashedPass 42 | If the hashes match, return **True**, else return **False** 43 | 44 | # Dictionary attack 45 | Extend guessing script to include 46 | - Reading plaintext password from a file 47 | - 1 at a time, tries the passwords 48 | - When a match is found, program quits and reports the correct password 49 | 50 | **NOTE:** For testing you may want to limit the dictionary file to ~10 passwords and use #5 as the hashed password 51 | Most common passwords pulled from https://github.com/danielmiessler/SecLists/tree/master/Passwords/Common-Credentials 52 | 53 | # Brute Force attack 54 | Example of how a brute force attack works. See image of bike combo lock with 4 numbers, each ranging 0-9 55 | ![](https://thebestbikelock.com/wp-content/uploads/2019/10/combination-lock.jpg) 56 | 57 | To brute force this, you start at `0000`, then `0001`, and so on until you reach `9999` or the correct answer 58 | If you dont know the length of the password, you start at `0` and keep going until `9999999999999` 59 | 60 | This example is similar to the Dictionary attack and uses same **testPass** function.Instead of reading from a file, we do a `for i in range(100000)` 61 | This example is simplified to only numbers. Use debugger if needed to highlight how each number in turn is being tested. 62 | 63 | More complex brute forcing includes larger character sets such as those shown below. This obviously complicates and slows the process, explaining why this may be the last choice in an attack 64 | - abcdefghijklmnopqrstuvwxyz 65 | - ABCDEFGHIJKLMNOPQRSTUVWXYZ 66 | - 0123456789 67 | - 0123456789abcdef 68 | - 0123456789ABCDEF 69 | - «space»!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 70 | - ?l?u?d?s 71 | - 0x00 - 0xff 72 | 73 | 74 | # Other suggestions 75 | Have students create process that separates hashed password into SALT and HASH so that it is no longer prompted 76 | Have students create script that opens a shadow file and pulls out the hashes for attacking 77 | -------------------------------------------------------------------------------- /end/CH06/bruteforceAttack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Example brute-force attacker 3 | #By Ed Goad 4 | # date: 2/5/2021 5 | 6 | # NOTE: this example is limited to numbers. 7 | # There are no letters or symbols in this example 8 | # Suggested to start by debugging to show how 9 | # brute force walks through all available options 10 | 11 | from passlib.hash import sha512_crypt 12 | 13 | def test_password(hashed_password, 14 | salt, plaintext_password): 15 | # Using the provided algorithm/salt and 16 | # plaintext password, create a hash 17 | crypted_password = sha512_crypt.using(rounds=5000).hash( 18 | plaintext_password, salt=salt) 19 | # Compare hashed_password with the just created hash 20 | if hashed_password == crypted_password: 21 | return True 22 | return False 23 | 24 | hashed_password = "$6$G.DTW7g9s5U7KYf5$QFcHx0/J88HV/Q0ab653" 25 | hashed_password += "gfYQ1KyNGx5HRhDQYyai2ZUy7Aw4tyfJ6/kI6kl" 26 | hashed_password += "lfXl0DyS.LuaUJvqnlIn2fVM5F0" 27 | salt = "G.DTW7g9s5U7KYf5" 28 | 29 | for password in range(100000): 30 | result = test_password(hashed_password, \ 31 | salt, str(password)) 32 | if result: 33 | print("Match found: {0}".format(password)) 34 | break 35 | -------------------------------------------------------------------------------- /end/CH06/dictionaryAttack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that performs a dictionary attack 3 | # against known password hashes 4 | # Needs a dictionary file to run. Suggested to use 5 | # https://github.com/danielmiessler/SecLists/tree/master/Passwords/Common-Credentials 6 | # By Ed Goad 7 | # date: 11/1/2004 8 | 9 | # Import necessary Python modules 10 | import os 11 | import sys 12 | from passlib.hash import sha512_crypt 13 | 14 | def test_password(hashed_password, 15 | salt, plaintext_password): 16 | # Using the provided algorithm/salt and 17 | # plaintext password, create a hash 18 | crypted_password = sha512_crypt.using(rounds=5000).hash( 19 | plaintext_password, salt=salt) 20 | # Compare hashed_password with the just created hash 21 | if hashed_password == crypted_password: 22 | return True 23 | return False 24 | 25 | def read_dictionary(dictionary_file): 26 | # Open provided dictionary file 27 | # and read contents into variable 28 | file_path = os.path.join(script_dir, dictionary_file) 29 | f = open(file_path, "r") 30 | message = f.read() 31 | return message 32 | 33 | # Get current file Directory 34 | script_path = os.path.abspath(__file__) 35 | script_dir = os.path.dirname(script_path) 36 | 37 | # Load dictionary file and prompt for hash 38 | password_dictionary = read_dictionary("top10.txt") 39 | hashed_password = input("What is the hashed password? ") 40 | hash_parts = hashed_password.split("$") 41 | salt = hash_parts[2] 42 | 43 | # For each password in dictionary file, 44 | # test against hashed_password 45 | for password in password_dictionary.splitlines(): 46 | result = test_password(hashed_password, salt, password) 47 | if result: 48 | # If a match is found, print it and quit 49 | print("Match found: {0}".format(password)) 50 | sys.exit() 51 | # No matches found, print error and quit 52 | print("No match found, try a different dictionary") 53 | -------------------------------------------------------------------------------- /end/CH06/passHasher.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password 3 | #By Ed Goad 4 | # date: 2/5/2021 5 | import crypt 6 | 7 | # Simple script that takes an unhashed password and a salt 8 | # We then hash the password + salt using various types 9 | 10 | # Sample data 11 | # Password: Password01 12 | # Salt: G.DTW7g9s5U7KYf5 13 | # SHA-512 result: 14 | # $6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p. 15 | 16 | plainPass = input("What is the password? ") 17 | salt = input("What is the salt? ") 18 | print("MD5 : {0}".format(crypt.crypt( \ 19 | plainPass,"$1$" + salt))) 20 | print("Blowfish : {0}".format(crypt.crypt( \ 21 | plainPass,"$2$" + salt))) 22 | print("eksblofish: {0}".format(crypt.crypt( \ 23 | plainPass,"$2a$" + salt))) 24 | print("SHA-256 : {0}".format(crypt.crypt( \ 25 | plainPass,"$5$" + salt))) 26 | print("SHA-512 : {0}".format(crypt.crypt( \ 27 | plainPass,"$6$" + salt))) 28 | 29 | -------------------------------------------------------------------------------- /end/CH06/shadow: -------------------------------------------------------------------------------- 1 | root:!:18830:0:99999:7::: 2 | daemon:*:18667:0:99999:7::: 3 | bin:*:18667:0:99999:7::: 4 | sys:*:18667:0:99999:7::: 5 | backup:*:18667:0:99999:7::: 6 | list:*:18667:0:99999:7::: 7 | irc:*:18667:0:99999:7::: 8 | gnats:*:18667:0:99999:7::: 9 | nobody:*:18667:0:99999:7::: 10 | gdm:*:18667:0:99999:7::: 11 | systemd-coredump:!!:18830:::::: 12 | hackme01:$6$ruzSF91zH9x9MeX6$WWWJ/9Is89yhYhGi.gCtTAePPIndPO8tf0Ux6NDs6QHfiTh//En9ftlpB5w9hYCxShv23YhmSruCwn4HP6xrU0:18886:0:99999:7::: 13 | hackme02:$6$O9OcwTwNbVKqK24q$FuVUpZsHC5uLLBSxUKYYpu6NzuSo/6tkmAyet8XyUsDy9g8v7WkEXbl4Rj6MW45xjl9Hyn15OGUdOPdkfJvVS.:18886:0:99999:7::: 14 | hackme03:$6$hqNeQoE5XBvDfEVk$OOJ0RWHMkG2PagKZukgA/swcQETLvGuoErUGkCEoLe3v7xZS6Fzc7nbIfXL1pdgk9jJNqyEOvsVUdNTblYjGy0:18886:0:99999:7::: 15 | hackme04:$6$ch8Vehhld0VzFI6y$6ccEIQVHGD7JE/Rskr12TSeNepKhejyub9g67BTM06ZHxQj1qJu9QDj0HiEM/d/03qgXU3i34sc4tFxz..Vln0:18886:0:99999:7::: 16 | hackme05:$6$/SODHa2dtiVj2hPK$VkNteUOBL6dg6ZbtkB3lZzlCJNR2i.eZF0yXxfh8Q1VsT6UzQ4/XVzHpy90snNR/4Ni4i55FrBgrLw3yI2aL60:18886:0:99999:7::: 17 | hackme06:$6$Zo9jq1UXAuEREPgV$LO8roNOpumamxda1TQ6TZcY.t5LF3cypAMboqWfQ1EokC.RcKnYERfrqzR5kkAKI4/TE6ysu6RkKEdwrz6pfS/:18886:0:99999:7::: 18 | hackme07:$6$9mxNwV65ywcAMSx3$.UOKPDgsj50EfJYajcQ4KBGgIEyY3QpkgKOvtNWMFq86xJLJ3KneiQD6pZMamXcVxtyvPEQjMvSF.nHI3Yj.T/:18886:0:99999:7::: 19 | hackme08:$6$6c/xO/skqVsSZgIA$0Avu1xnlg/nr5pcLF5CujYTlbmixkiAbFSITC/lqOkKmNZsh4zGeQml1Bfx58dgxPMI3g0BjyGT4FinTKf3JO.:18886:0:99999:7::: 20 | hackme09:$6$wjQCpm0A2rkutLJN$vF7GcHfuFBdb2E4t9XaGOytR5rW43nIhUcpErzpWKFV6q7T9QMMXs6iJZyWohTSffcMncyZaOUzyT7wKGdi5M1:18886:0:99999:7::: 21 | hackme10:$6$m96VAMjtUMd8qtSm$ilet44..E0ZYLkPEkVeewpMjQSa0Tl8Uy1scEJLNch1DA4sZ3nsCuSFP0YBttGOnwbX5ySJoTjixHZgGSQfDB/:18886:0:99999:7::: 22 | hackme11:$6$wlJ7egutqr6ZqZh3$sMp2f2DjDKnyS6nDRSNOY3sfeMPZfbK73.eqe03CvqbTZ79e8bR9cUJCojCOHQKwxzbdCahplHzB8FZhNgn6T/:18886:0:99999:7::: 23 | hackme12:$6$u3Ny9M9DbSLqRBkI$r1IVUrGJj2/5WyDhi4KWB9NJ9uorTvX8a7aTzWI9rPdgRHKcMkLTT0Cuz3dSsq.WzmTvpA5Nswoy.2mrmILJX.:18886:0:99999:7::: 24 | hackme13:$6$DSBiJzN/zdd3.G3c$WR5STYPORyo9lzuoHdchRenZ2CSMMU6tv4JQcZS1crEOOy8Q4YUPEWF6BZcio94UC1wE37JnYzlAQBUdpRAjb0:18886:0:99999:7::: 25 | hackme14:$6$5hmepsiG9GimaTq8$nNZGCVj7MGF/6gDcYwxOu1ZzKQpzpbimn6Mwl1Wcb3otJi61Vbfcf9X674a6srUQbZMR4wGlrYg8afMauaZLP1:18886:0:99999:7::: 26 | hackme15:$6$AdG35bS8xEbKnc/V$UMoj8lcgtviIpbwGpeHbqG5vrdmAs.Nv4wFsqyv2fvQlW2O.g0oNtO77zSISMP8GS4FqzgRCjaUxxYxTl2Ly2/:18886:0:99999:7::: 27 | hackme16:$6$PfBwY10JPwvdEprh$mcJ1AVJXqRiXnhcap8toF2HCUPDz5gnNobQ8UTk.UkBP7XFe00NeV.cRylUlKWuEPOB4y9VktUJiTeftX0oL7.:18886:0:99999:7::: 28 | hackme17:$6$GI2cH8zAmWH.3wNl$sxqPYl8Nd2C0fJeD6NN4DwV7UhL/4bnp.rZLOKq24f8nl4fUmzbhYH.QOkXxZHmt35GyG9TYNacj4REK2LYB/.:18886:0:99999:7::: 29 | hackme18:$6$9jRhBbxUBQKFpgRY$L3PIQcXtba1.A3vpm10l2/phsUBcYkcitJUQPltF/TXh11BJMxIfRsPYJkR8DunInaukO7nFD084NEyNc8Ut41:18886:0:99999:7::: 30 | hackme19:$6$Yy2AVSdSGxefRjep$nB2tF.MMpl6/oJAayuLdOWFYyhjyeu7CRE5v6/OjW2Y91pd540SqXsTtzProS.U4CSDM2K24.VQwuLU5xRLEU/:18886:0:99999:7::: 31 | hackme20:$6$wZ0.Jc/vbgQNMuF3$gbKUkWvvvR/lOmtATn3N9wPHERkWqIqOd9pJVGS3zHcZ64P9oekEoT89x1wXRaw8hSb78SFQK2mfNYjVyaC6P0:18886:0:99999:7::: 32 | -------------------------------------------------------------------------------- /end/CH06/top10.txt: -------------------------------------------------------------------------------- 1 | 123456 2 | password 3 | 12345678 4 | qwerty 5 | 123456789 6 | 12345 7 | 1234 8 | 111111 9 | 1234567 10 | dragon 11 | -------------------------------------------------------------------------------- /end/CH06/top1000.txt: -------------------------------------------------------------------------------- 1 | 123456 2 | password 3 | 12345678 4 | qwerty 5 | 123456789 6 | 12345 7 | 1234 8 | 111111 9 | 1234567 10 | dragon 11 | 123123 12 | baseball 13 | abc123 14 | football 15 | monkey 16 | letmein 17 | 696969 18 | shadow 19 | master 20 | 666666 21 | qwertyuiop 22 | 123321 23 | mustang 24 | 1234567890 25 | michael 26 | 654321 27 | pussy 28 | superman 29 | 1qaz2wsx 30 | 7777777 31 | fuckyou 32 | 121212 33 | 000000 34 | qazwsx 35 | 123qwe 36 | killer 37 | trustno1 38 | jordan 39 | jennifer 40 | zxcvbnm 41 | asdfgh 42 | hunter 43 | buster 44 | soccer 45 | harley 46 | batman 47 | andrew 48 | tigger 49 | sunshine 50 | iloveyou 51 | fuckme 52 | 2000 53 | charlie 54 | robert 55 | thomas 56 | hockey 57 | ranger 58 | daniel 59 | starwars 60 | klaster 61 | 112233 62 | george 63 | asshole 64 | computer 65 | michelle 66 | jessica 67 | pepper 68 | 1111 69 | zxcvbn 70 | 555555 71 | 11111111 72 | 131313 73 | freedom 74 | 777777 75 | pass 76 | fuck 77 | maggie 78 | 159753 79 | aaaaaa 80 | ginger 81 | princess 82 | joshua 83 | cheese 84 | amanda 85 | summer 86 | love 87 | ashley 88 | 6969 89 | nicole 90 | chelsea 91 | biteme 92 | matthew 93 | access 94 | yankees 95 | 987654321 96 | dallas 97 | austin 98 | thunder 99 | taylor 100 | matrix 101 | william 102 | corvette 103 | hello 104 | martin 105 | heather 106 | secret 107 | fucker 108 | merlin 109 | diamond 110 | 1234qwer 111 | gfhjkm 112 | hammer 113 | silver 114 | 222222 115 | 88888888 116 | anthony 117 | justin 118 | test 119 | bailey 120 | q1w2e3r4t5 121 | patrick 122 | internet 123 | scooter 124 | orange 125 | 11111 126 | golfer 127 | cookie 128 | richard 129 | samantha 130 | bigdog 131 | guitar 132 | jackson 133 | whatever 134 | mickey 135 | chicken 136 | sparky 137 | snoopy 138 | maverick 139 | phoenix 140 | camaro 141 | sexy 142 | peanut 143 | morgan 144 | welcome 145 | falcon 146 | cowboy 147 | ferrari 148 | samsung 149 | andrea 150 | smokey 151 | steelers 152 | joseph 153 | mercedes 154 | dakota 155 | arsenal 156 | eagles 157 | melissa 158 | boomer 159 | booboo 160 | spider 161 | nascar 162 | monster 163 | tigers 164 | yellow 165 | xxxxxx 166 | 123123123 167 | gateway 168 | marina 169 | diablo 170 | bulldog 171 | qwer1234 172 | compaq 173 | purple 174 | hardcore 175 | banana 176 | junior 177 | hannah 178 | 123654 179 | porsche 180 | lakers 181 | iceman 182 | money 183 | cowboys 184 | 987654 185 | london 186 | tennis 187 | 999999 188 | ncc1701 189 | coffee 190 | scooby 191 | 0000 192 | miller 193 | boston 194 | q1w2e3r4 195 | fuckoff 196 | brandon 197 | yamaha 198 | chester 199 | mother 200 | forever 201 | johnny 202 | edward 203 | 333333 204 | oliver 205 | redsox 206 | player 207 | nikita 208 | knight 209 | fender 210 | barney 211 | midnight 212 | please 213 | brandy 214 | chicago 215 | badboy 216 | iwantu 217 | slayer 218 | rangers 219 | charles 220 | angel 221 | flower 222 | bigdaddy 223 | rabbit 224 | wizard 225 | bigdick 226 | jasper 227 | enter 228 | rachel 229 | chris 230 | steven 231 | winner 232 | adidas 233 | victoria 234 | natasha 235 | 1q2w3e4r 236 | jasmine 237 | winter 238 | prince 239 | panties 240 | marine 241 | ghbdtn 242 | fishing 243 | cocacola 244 | casper 245 | james 246 | 232323 247 | raiders 248 | 888888 249 | marlboro 250 | gandalf 251 | asdfasdf 252 | crystal 253 | 87654321 254 | 12344321 255 | sexsex 256 | golden 257 | blowme 258 | bigtits 259 | 8675309 260 | panther 261 | lauren 262 | angela 263 | bitch 264 | spanky 265 | thx1138 266 | angels 267 | madison 268 | winston 269 | shannon 270 | mike 271 | toyota 272 | blowjob 273 | jordan23 274 | canada 275 | sophie 276 | Password 277 | apples 278 | dick 279 | tiger 280 | razz 281 | 123abc 282 | pokemon 283 | qazxsw 284 | 55555 285 | qwaszx 286 | muffin 287 | johnson 288 | murphy 289 | cooper 290 | jonathan 291 | liverpoo 292 | david 293 | danielle 294 | 159357 295 | jackie 296 | 1990 297 | 123456a 298 | 789456 299 | turtle 300 | horny 301 | abcd1234 302 | scorpion 303 | qazwsxedc 304 | 101010 305 | butter 306 | carlos 307 | password1 308 | dennis 309 | slipknot 310 | qwerty123 311 | booger 312 | asdf 313 | 1991 314 | black 315 | startrek 316 | 12341234 317 | cameron 318 | newyork 319 | rainbow 320 | nathan 321 | john 322 | 1992 323 | rocket 324 | viking 325 | redskins 326 | butthead 327 | asdfghjkl 328 | 1212 329 | sierra 330 | peaches 331 | gemini 332 | doctor 333 | wilson 334 | sandra 335 | helpme 336 | qwertyui 337 | victor 338 | florida 339 | dolphin 340 | pookie 341 | captain 342 | tucker 343 | blue 344 | liverpool 345 | theman 346 | bandit 347 | dolphins 348 | maddog 349 | packers 350 | jaguar 351 | lovers 352 | nicholas 353 | united 354 | tiffany 355 | maxwell 356 | zzzzzz 357 | nirvana 358 | jeremy 359 | suckit 360 | stupid 361 | porn 362 | monica 363 | elephant 364 | giants 365 | jackass 366 | hotdog 367 | rosebud 368 | success 369 | debbie 370 | mountain 371 | 444444 372 | xxxxxxxx 373 | warrior 374 | 1q2w3e4r5t 375 | q1w2e3 376 | 123456q 377 | albert 378 | metallic 379 | lucky 380 | azerty 381 | 7777 382 | shithead 383 | alex 384 | bond007 385 | alexis 386 | 1111111 387 | samson 388 | 5150 389 | willie 390 | scorpio 391 | bonnie 392 | gators 393 | benjamin 394 | voodoo 395 | driver 396 | dexter 397 | 2112 398 | jason 399 | calvin 400 | freddy 401 | 212121 402 | creative 403 | 12345a 404 | sydney 405 | rush2112 406 | 1989 407 | asdfghjk 408 | red123 409 | bubba 410 | 4815162342 411 | passw0rd 412 | trouble 413 | gunner 414 | happy 415 | fucking 416 | gordon 417 | legend 418 | jessie 419 | stella 420 | qwert 421 | eminem 422 | arthur 423 | apple 424 | nissan 425 | bullshit 426 | bear 427 | america 428 | 1qazxsw2 429 | nothing 430 | parker 431 | 4444 432 | rebecca 433 | qweqwe 434 | garfield 435 | 01012011 436 | beavis 437 | 69696969 438 | jack 439 | asdasd 440 | december 441 | 2222 442 | 102030 443 | 252525 444 | 11223344 445 | magic 446 | apollo 447 | skippy 448 | 315475 449 | girls 450 | kitten 451 | golf 452 | copper 453 | braves 454 | shelby 455 | godzilla 456 | beaver 457 | fred 458 | tomcat 459 | august 460 | buddy 461 | airborne 462 | 1993 463 | 1988 464 | lifehack 465 | qqqqqq 466 | brooklyn 467 | animal 468 | platinum 469 | phantom 470 | online 471 | xavier 472 | darkness 473 | blink182 474 | power 475 | fish 476 | green 477 | 789456123 478 | voyager 479 | police 480 | travis 481 | 12qwaszx 482 | heaven 483 | snowball 484 | lover 485 | abcdef 486 | 00000 487 | pakistan 488 | 007007 489 | walter 490 | playboy 491 | blazer 492 | cricket 493 | sniper 494 | hooters 495 | donkey 496 | willow 497 | loveme 498 | saturn 499 | therock 500 | redwings 501 | bigboy 502 | pumpkin 503 | trinity 504 | williams 505 | tits 506 | nintendo 507 | digital 508 | destiny 509 | topgun 510 | runner 511 | marvin 512 | guinness 513 | chance 514 | bubbles 515 | testing 516 | fire 517 | november 518 | minecraft 519 | asdf1234 520 | lasvegas 521 | sergey 522 | broncos 523 | cartman 524 | private 525 | celtic 526 | birdie 527 | little 528 | cassie 529 | babygirl 530 | donald 531 | beatles 532 | 1313 533 | dickhead 534 | family 535 | 12121212 536 | school 537 | louise 538 | gabriel 539 | eclipse 540 | fluffy 541 | 147258369 542 | lol123 543 | explorer 544 | beer 545 | nelson 546 | flyers 547 | spencer 548 | scott 549 | lovely 550 | gibson 551 | doggie 552 | cherry 553 | andrey 554 | snickers 555 | buffalo 556 | pantera 557 | metallica 558 | member 559 | carter 560 | qwertyu 561 | peter 562 | alexande 563 | steve 564 | bronco 565 | paradise 566 | goober 567 | 5555 568 | samuel 569 | montana 570 | mexico 571 | dreams 572 | michigan 573 | cock 574 | carolina 575 | yankee 576 | friends 577 | magnum 578 | surfer 579 | poopoo 580 | maximus 581 | genius 582 | cool 583 | vampire 584 | lacrosse 585 | asd123 586 | aaaa 587 | christin 588 | kimberly 589 | speedy 590 | sharon 591 | carmen 592 | 111222 593 | kristina 594 | sammy 595 | racing 596 | ou812 597 | sabrina 598 | horses 599 | 0987654321 600 | qwerty1 601 | pimpin 602 | baby 603 | stalker 604 | enigma 605 | 147147 606 | star 607 | poohbear 608 | boobies 609 | 147258 610 | simple 611 | bollocks 612 | 12345q 613 | marcus 614 | brian 615 | 1987 616 | qweasdzxc 617 | drowssap 618 | hahaha 619 | caroline 620 | barbara 621 | dave 622 | viper 623 | drummer 624 | action 625 | einstein 626 | bitches 627 | genesis 628 | hello1 629 | scotty 630 | friend 631 | forest 632 | 010203 633 | hotrod 634 | google 635 | vanessa 636 | spitfire 637 | badger 638 | maryjane 639 | friday 640 | alaska 641 | 1232323q 642 | tester 643 | jester 644 | jake 645 | champion 646 | billy 647 | 147852 648 | rock 649 | hawaii 650 | badass 651 | chevy 652 | 420420 653 | walker 654 | stephen 655 | eagle1 656 | bill 657 | 1986 658 | october 659 | gregory 660 | svetlana 661 | pamela 662 | 1984 663 | music 664 | shorty 665 | westside 666 | stanley 667 | diesel 668 | courtney 669 | 242424 670 | kevin 671 | porno 672 | hitman 673 | boobs 674 | mark 675 | 12345qwert 676 | reddog 677 | frank 678 | qwe123 679 | popcorn 680 | patricia 681 | aaaaaaaa 682 | 1969 683 | teresa 684 | mozart 685 | buddha 686 | anderson 687 | paul 688 | melanie 689 | abcdefg 690 | security 691 | lucky1 692 | lizard 693 | denise 694 | 3333 695 | a12345 696 | 123789 697 | ruslan 698 | stargate 699 | simpsons 700 | scarface 701 | eagle 702 | 123456789a 703 | thumper 704 | olivia 705 | naruto 706 | 1234554321 707 | general 708 | cherokee 709 | a123456 710 | vincent 711 | Usuckballz1 712 | spooky 713 | qweasd 714 | cumshot 715 | free 716 | frankie 717 | douglas 718 | death 719 | 1980 720 | loveyou 721 | kitty 722 | kelly 723 | veronica 724 | suzuki 725 | semperfi 726 | penguin 727 | mercury 728 | liberty 729 | spirit 730 | scotland 731 | natalie 732 | marley 733 | vikings 734 | system 735 | sucker 736 | king 737 | allison 738 | marshall 739 | 1979 740 | 098765 741 | qwerty12 742 | hummer 743 | adrian 744 | 1985 745 | vfhbyf 746 | sandman 747 | rocky 748 | leslie 749 | antonio 750 | 98765432 751 | 4321 752 | softball 753 | passion 754 | mnbvcxz 755 | bastard 756 | passport 757 | horney 758 | rascal 759 | howard 760 | franklin 761 | bigred 762 | assman 763 | alexander 764 | homer 765 | redrum 766 | jupiter 767 | claudia 768 | 55555555 769 | 141414 770 | zaq12wsx 771 | shit 772 | patches 773 | nigger 774 | cunt 775 | raider 776 | infinity 777 | andre 778 | 54321 779 | galore 780 | college 781 | russia 782 | kawasaki 783 | bishop 784 | 77777777 785 | vladimir 786 | money1 787 | freeuser 788 | wildcats 789 | francis 790 | disney 791 | budlight 792 | brittany 793 | 1994 794 | 00000000 795 | sweet 796 | oksana 797 | honda 798 | domino 799 | bulldogs 800 | brutus 801 | swordfis 802 | norman 803 | monday 804 | jimmy 805 | ironman 806 | ford 807 | fantasy 808 | 9999 809 | 7654321 810 | PASSWORD 811 | hentai 812 | duncan 813 | cougar 814 | 1977 815 | jeffrey 816 | house 817 | dancer 818 | brooke 819 | timothy 820 | super 821 | marines 822 | justice 823 | digger 824 | connor 825 | patriots 826 | karina 827 | 202020 828 | molly 829 | everton 830 | tinker 831 | alicia 832 | rasdzv3 833 | poop 834 | pearljam 835 | stinky 836 | naughty 837 | colorado 838 | 123123a 839 | water 840 | test123 841 | ncc1701d 842 | motorola 843 | ireland 844 | asdfg 845 | slut 846 | matt 847 | houston 848 | boogie 849 | zombie 850 | accord 851 | vision 852 | bradley 853 | reggie 854 | kermit 855 | froggy 856 | ducati 857 | avalon 858 | 6666 859 | 9379992 860 | sarah 861 | saints 862 | logitech 863 | chopper 864 | 852456 865 | simpson 866 | madonna 867 | juventus 868 | claire 869 | 159951 870 | zachary 871 | yfnfif 872 | wolverin 873 | warcraft 874 | hello123 875 | extreme 876 | penis 877 | peekaboo 878 | fireman 879 | eugene 880 | brenda 881 | 123654789 882 | russell 883 | panthers 884 | georgia 885 | smith 886 | skyline 887 | jesus 888 | elizabet 889 | spiderma 890 | smooth 891 | pirate 892 | empire 893 | bullet 894 | 8888 895 | virginia 896 | valentin 897 | psycho 898 | predator 899 | arizona 900 | 134679 901 | mitchell 902 | alyssa 903 | vegeta 904 | titanic 905 | christ 906 | goblue 907 | fylhtq 908 | wolf 909 | mmmmmm 910 | kirill 911 | indian 912 | hiphop 913 | baxter 914 | awesome 915 | people 916 | danger 917 | roland 918 | mookie 919 | 741852963 920 | 1111111111 921 | Password01 922 | dreamer 923 | bambam 924 | arnold 925 | 1981 926 | skipper 927 | serega 928 | rolltide 929 | elvis 930 | changeme 931 | simon 932 | 1q2w3e 933 | lovelove 934 | fktrcfylh 935 | denver 936 | tommy 937 | mine 938 | loverboy 939 | hobbes 940 | happy1 941 | alison 942 | nemesis 943 | chevelle 944 | cardinal 945 | burton 946 | wanker 947 | picard 948 | 151515 949 | tweety 950 | michael1 951 | 147852369 952 | 12312 953 | xxxx 954 | windows 955 | turkey 956 | 456789 957 | 1974 958 | vfrcbv 959 | sublime 960 | 1975 961 | galina 962 | bobby 963 | newport 964 | manutd 965 | daddy 966 | american 967 | alexandr 968 | 1966 969 | victory 970 | rooster 971 | qqq111 972 | madmax 973 | electric 974 | bigcock 975 | a1b2c3 976 | wolfpack 977 | spring 978 | phpbb 979 | lalala 980 | suckme 981 | spiderman 982 | eric 983 | darkside 984 | classic 985 | raptor 986 | 123456789q 987 | hendrix 988 | 1982 989 | wombat 990 | avatar 991 | alpha 992 | zxc123 993 | crazy 994 | hard 995 | england 996 | brazil 997 | 1978 998 | 01011980 999 | wildcat 1000 | polina 1001 | freepass 1002 | -------------------------------------------------------------------------------- /end/CH07/Find404.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for 404 errors 3 | # By Ed Goad 4 | # date: 12/16 5 | 6 | import os 7 | 8 | # Prompt for file to analyze 9 | log_file = input("Which file to analyze? ") 10 | 11 | # Get current file Directory 12 | script_path = os.path.abspath(__file__) 13 | script_dir = os.path.dirname(script_path) 14 | file_path = os.path.join(script_dir, log_file) 15 | 16 | # Open file 17 | f = open(file_path, "r") 18 | 19 | # Read file line by line 20 | while True: 21 | line = f.readline() 22 | if not line: 23 | break 24 | # Check for 404 25 | if "404" in line: 26 | print(line.strip()) 27 | 28 | # Close file 29 | f.close() 30 | -------------------------------------------------------------------------------- /end/CH07/FindClients.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for client addresses 3 | # Use RegEx to find and report on most frequent users 4 | # By Ed Goad 5 | # date: 12/16 6 | 7 | #Import Python modules 8 | import os 9 | import re 10 | 11 | # Prompt for file to analyze 12 | log_file = input("Which file to analyze? ") 13 | 14 | # Get current file Directory 15 | script_path = os.path.abspath(__file__) 16 | script_dir = os.path.dirname(script_path) 17 | file_path = os.path.join(script_dir, log_file) 18 | 19 | # Open file and load into memory 20 | with open(file_path, "r") as f: 21 | sample_logs = f.readlines() 22 | 23 | # Setup regex pattern and empty dictionary 24 | client_pattern = r'(^\S+\.[\S+\.]+\S+)\s' 25 | clientdict = {} 26 | 27 | # Find match and store in dictionary 28 | for line in sample_logs: 29 | # Search for pattern, and if found move forward 30 | m = re.search(client_pattern, line) 31 | if m: 32 | client = m.group(1) 33 | # Put access frequency in dictionary 34 | if client in clientdict.keys(): 35 | clientdict[client] += 1 36 | else: 37 | clientdict[client] = 1 38 | 39 | 40 | # Sort by most frequently accessed 41 | for w in sorted(clientdict, key=clientdict.get, reverse=False): 42 | print(w, clientdict[w]) 43 | -------------------------------------------------------------------------------- /end/CH07/FindPotentialHacking.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for possible hacking 3 | # Use RegEx to find and report on common hacking types 4 | # Based on 5 | # https://www.cgisecurity.com/fingerprinting-port-80-attacks-a-look-into-web-server-and-web-application-attack-signatures.html 6 | # and 7 | # https://www.cgisecurity.com/fingerprinting-port80-attacks-a-look-into-web-server-and-web-application-attack-signatures-part-two.html 8 | # By Ed Goad 9 | # date: 2/5/2021 10 | 11 | #Import Python modules 12 | import os 13 | import re 14 | 15 | # Prompt for file to analyze 16 | log_file = input("Which file to analyze? ") 17 | 18 | # Get current file Directory 19 | script_path = os.path.abspath(__file__) 20 | script_dir = os.path.dirname(script_path) 21 | file_path = os.path.join(script_dir, log_file) 22 | 23 | # Open file and load into memory 24 | with open(file_path, "r") as f: 25 | sample_logs = f.readlines() 26 | 27 | # Setup regex patterns 28 | request_start = r'"\w+ ([^"]*' 29 | request_end = r'[^"]*) HTTP\/\d\.\d"' 30 | find_wildcard_uri_pattern = request_start + r'\*' + request_end 31 | find_backtick_uri_pattern = request_start + r'`' + request_end 32 | find_code_uri_pattern = request_start + r'[\^\[\]#{}\"]' + request_end 33 | find_css_uri_pattern = request_start + r'[\(\)]' + request_end 34 | find_foldertraversal_uri_pattern = request_start + r'\.{2,}' + request_end 35 | 36 | # Find match and report 37 | for line in sample_logs: 38 | # Search for pattern, and if found move forward 39 | m = re.search(find_wildcard_uri_pattern, line) 40 | if m: 41 | print("Possible attack: Wildcard in URI") 42 | print("\t{0}".format(line.strip())) 43 | m = re.search(find_backtick_uri_pattern, line) 44 | if m: 45 | print("Possible attack: Backtick (`) in URI") 46 | print("\t{0}".format(line.strip())) 47 | m = re.search(find_code_uri_pattern, line) 48 | if m: 49 | print("Possible attack: Code in URI") 50 | print("\t{0}".format(line.strip())) 51 | m = re.search(find_css_uri_pattern, line) 52 | if m: 53 | print("Possible attack: Potential CSS in URI") 54 | print("\t{0}".format(line.strip())) 55 | m = re.search(find_foldertraversal_uri_pattern, line) 56 | if m: 57 | print("Possible attack: Folder Traversal in URI") 58 | print("\t{0}".format(line.strip())) 59 | 60 | -------------------------------------------------------------------------------- /end/CH07/FindStatusCodes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for status codes 3 | # Use RegEx to find and report on most frequent status messages 4 | # By Ed Goad 5 | # date: 12/16 6 | 7 | #Import Python modules 8 | import os 9 | import re 10 | 11 | # Prompt for file to analyze 12 | log_file = input("Which file to analyze? ") 13 | 14 | # Get current file Directory 15 | script_path = os.path.abspath(__file__) 16 | script_dir = os.path.dirname(script_path) 17 | file_path = os.path.join(script_dir, log_file) 18 | 19 | # Open file and load into memory 20 | with open(file_path, "r") as f: 21 | sample_logs = f.readlines() 22 | 23 | # Setup regex pattern and empty dictionary 24 | status_pattern = r'\s(\d{3})\s' 25 | statusdict = {} 26 | 27 | # Find match and store in dictionary 28 | for line in sample_logs: 29 | # Search for pattern, and if found move forward 30 | m = re.search(status_pattern, line) 31 | if m: 32 | result = m.group(1) 33 | # Put access frequency in dictionary 34 | if result in statusdict.keys(): 35 | statusdict[result] += 1 36 | else: 37 | statusdict[result] = 1 38 | 39 | # Sort by most frequently accessed 40 | for w in sorted(statusdict, key=statusdict.get, reverse=False): 41 | print(w, statusdict[w]) 42 | -------------------------------------------------------------------------------- /end/CH07/README.md: -------------------------------------------------------------------------------- 1 | geolocation api: https://ipstack.com/ 2 | 3 | Im not happy with the geolocate 4 | I think it would be better to further analyze the apache logs for hacking 5 | 6 | possibly include regex examples for CC#, SSN# or other interesting info 7 | 8 | 9 | access.log pulled from http://www.almhuette-raith.at/apache-log/access.log on 3/23/2021 10 | need to sanitize -------------------------------------------------------------------------------- /end/CH08/HaveIBeenPwned.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that checks passwords against haveibeenpwned.com API 3 | # https://haveibeenpwned.com/API/v3#PwnedPasswords 4 | # By Ed Goad 5 | # date: 12/19 6 | 7 | # Import Python modules 8 | import requests 9 | import hashlib 10 | 11 | def sha1_hash(text): 12 | sha1 = hashlib.sha1() 13 | sha1.update(text.encode('utf-8')) 14 | return sha1.hexdigest() 15 | 16 | def check_haveibeenpwned(sha_prefix): 17 | # create empty dictionary 18 | pwnd_dict = {} 19 | 20 | # send request to API 21 | request_uri = "https://api.pwnedpasswords.com/range/" + sha_prefix 22 | r = requests.get(request_uri) 23 | 24 | # Separate list by newline 25 | pwnd_list = r.text.split("\r\n") 26 | for pwnd_pass in pwnd_list: 27 | # Separate each line by colon 28 | pwnd_hash = pwnd_pass.split(":") 29 | # add hash and value to dictionary 30 | pwnd_dict[pwnd_hash[0]] = pwnd_hash[1] 31 | 32 | # return dictionary 33 | return pwnd_dict 34 | 35 | # get password to check 36 | password = input("What password needs to be checked? ") 37 | # get SHA-1 hash of password 38 | sha_password = sha1_hash(password).upper() 39 | # slice hash at the 5th character 40 | sha_prefix = sha_password[0:5] 41 | sha_postfix = sha_password[5:] 42 | 43 | # call API with first 5 characters 44 | pwnd_dict = check_haveibeenpwned(sha_prefix) 45 | 46 | # check if hash is in results 47 | if sha_postfix in pwnd_dict.keys(): 48 | print("Password has been compromised {0} times".format( 49 | pwnd_dict[sha_postfix])) 50 | else: 51 | print("Password has not been compromised. It is safe to use!") 52 | -------------------------------------------------------------------------------- /end/CH08/ListRepositories.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that lists repositories in GitHub 3 | # Requires a Personal Access Token to run 4 | # By Ed Goad 5 | # date: 1/3 6 | 7 | # Import Python modules 8 | import os 9 | import requests 10 | import configparser 11 | 12 | def get_api_key(key_name): 13 | # Get the location of the secrets file 14 | home_dir = os.path.expanduser("~") 15 | secrets_file = os.path.join(home_dir, "secrets.ini") 16 | # Create the ConfigParser and load the file 17 | config = configparser.ConfigParser() 18 | config.read(secrets_file) 19 | # Get the API key and return 20 | api_key = config["APIKeys"][key_name] 21 | return api_key 22 | 23 | def list_respositores(token): 24 | # Setup the base URL and Authorization header 25 | url = "https://api.github.com/user/repos" 26 | headers = { 'Authorization' : "Bearer " + token } 27 | # Perform the request 28 | response = requests.get( 29 | url, 30 | headers=headers 31 | ) 32 | # Convert the JSON to Python objects 33 | items = response.json() 34 | return items 35 | 36 | # Get API key from file 37 | token = get_api_key("GitHub") 38 | 39 | # Get repositories 40 | repositories = list_respositores(token) 41 | # For each repo, print out the name 42 | for repository in repositories: 43 | print(repository["name"]) 44 | 45 | -------------------------------------------------------------------------------- /end/CH08/PeopleInSpace1.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = "http://api.open-notify.org/astros.json" 4 | 5 | payload = {} 6 | headers = {} 7 | 8 | response = requests.request("GET", url, headers=headers, data=payload) 9 | 10 | print(response.text) 11 | -------------------------------------------------------------------------------- /end/CH08/PeopleInSpace2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that tells us how many people there are in space 3 | # By Ed Goad 4 | # date: 12/19 5 | 6 | # Import Python modules 7 | import requests 8 | import json 9 | 10 | def get_people_in_space(): 11 | request_uri = "http://api.open-notify.org/astros.json" 12 | r = requests.get(request_uri) 13 | items = r.json() 14 | return items 15 | 16 | astronauts = get_people_in_space() 17 | 18 | # print basic details 19 | print(astronauts) 20 | 21 | # print "pretty" json 22 | print( json.dumps(astronauts, indent=2) ) 23 | 24 | # return the number of people in space 25 | print("There are {0} people in space right now".format( 26 | astronauts["number"])) 27 | 28 | # search through data to return specific information 29 | print("The first astronaut is {0} aboard the {1}".format( 30 | astronauts["people"][0]["name"], 31 | astronauts["people"][0]["craft"])) 32 | 33 | # Loop through all the people 34 | print("Full list of people in space") 35 | for person in astronauts["people"]: 36 | print("{0} is aboard the {1}".format( 37 | person["name"], 38 | person["craft"])) -------------------------------------------------------------------------------- /end/CH09/CheckURL.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that checks URLs against Google's Safe Browsing API 3 | # https://developers.google.com/safe-browsing/v4 4 | # By Ed Goad 5 | # date: 2/5 6 | 7 | # Import Python modules 8 | import requests 9 | import configparser 10 | import os 11 | 12 | def get_api_key(key_name): 13 | # Get the location of the secrets file 14 | home_dir = os.path.expanduser( "~" ) 15 | secrets_file = os.path.join(home_dir, "secrets.ini" ) 16 | # Create the ConfigParser and load the file 17 | config = configparser.ConfigParser() 18 | config.read(secrets_file) 19 | # Get the API key and return 20 | api_key = config["APIKeys"][key_name] 21 | return api_key 22 | 23 | def check_safebrowsing_url(token, threat, platform, test_url): 24 | clientId = "test_python_client" 25 | clientVersion = "0.0.1" 26 | # Setup the base URL and Authorization header 27 | api_base = "https://safebrowsing.googleapis.com/v4" 28 | url = api_base + "/threatMatches:find?key=" + token 29 | # Configure API key and file hash 30 | params = { "client": { 31 | "clientId": clientId, 32 | "clientVersion": clientVersion 33 | }, 34 | "threatInfo": { 35 | "threatTypes": threat, 36 | "platformTypes": platform, 37 | "threatEntryTypes": "URL", 38 | "threatEntries": { 39 | "url": test_url 40 | } 41 | } 42 | } 43 | # Perform the request 44 | response = requests.post( 45 | url, 46 | json=params 47 | ) 48 | # Convert the JSON to Python objects 49 | items = response.json() 50 | return items 51 | 52 | 53 | # Get API key 54 | token = get_api_key("GoogleSafeBrowsing") 55 | 56 | # Prompt user for platformTypes, Default to "LINUX" 57 | platform = input("What platform are you scanning from [LINUX] ") or "LINUX" 58 | 59 | # Default threatTypes to "MALWARE" 60 | threat = input("What threat type [MALWARE] ") or "MALWARE" 61 | 62 | # Prompt user for threatEntries 63 | url = input("What URL to scan? ") or "http://testsafebrowsing.appspot.com/s/malware.html" 64 | 65 | scan_results = check_safebrowsing_url(token, threat, platform, url) 66 | if "matches" in scan_results: 67 | print("Threats found") 68 | matches = scan_results["matches"] 69 | for match in matches: 70 | print("\t" + 71 | match["platformType"] + 72 | " / " + match["threatType"] + 73 | ": " + match["threat"]["url"] 74 | ) 75 | else: 76 | print("No issues found") -------------------------------------------------------------------------------- /end/CH09/ScanFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans files using VirusTotal API 3 | # https://developers.virustotal.com/reference 4 | # By Ed Goad 5 | # date: 2/5 6 | 7 | # Import Python modules 8 | import requests 9 | import hashlib 10 | import configparser 11 | import time 12 | import os 13 | import sys 14 | 15 | def get_api_key(key_name): 16 | # Get the location of the secrets file 17 | home_dir = os.path.expanduser( "~" ) 18 | secrets_file = os.path.join(home_dir, "secrets.ini" ) 19 | # Create the ConfigParser and load the file 20 | config = configparser.ConfigParser() 21 | config.read(secrets_file) 22 | # Get the API key and return 23 | api_key = config["APIKeys"][key_name] 24 | return api_key 25 | 26 | def virustotal_get_file_report(token, hash): 27 | # Setup the URL 28 | url = api_base + "/files/" + hash 29 | # Configure API key 30 | headers = { 31 | 'x-apikey': token, 32 | 'accept': 'application/json' 33 | } 34 | payload = {} 35 | # Perform the request 36 | response = requests.get( 37 | url, 38 | headers = headers, 39 | data = payload 40 | ) 41 | # Convert the JSON to Python objects 42 | if response.status_code == 200: 43 | items = response.json() 44 | return items 45 | 46 | def virustotal_get_analysis(token, id): 47 | # Setup the URL 48 | url = api_base + "/analyses/" + id 49 | # Configure API key 50 | headers = { 51 | 'x-apikey': token, 52 | 'accept': 'application/json' 53 | } 54 | payload = {} 55 | # Perform the request 56 | response = requests.get( 57 | url, 58 | headers = headers, 59 | data = payload 60 | ) 61 | # Convert the JSON to Python objects 62 | if response.status_code == 200: 63 | items = response.json() 64 | return items 65 | 66 | def virustotal_upload_file(token, file_path): 67 | # Setup the base URL and Authorization header 68 | url = api_base + "/files" 69 | # Configure API key 70 | headers = { 71 | 'x-apikey': token, 72 | 'accept': 'application/json' 73 | } 74 | 75 | # Separate file_name from file_path 76 | file_name = os.path.basename(file_path) 77 | # Setup file for upload 78 | files = { 79 | 'file': ( 80 | file_name, 81 | open(file_path, 'rb') 82 | ) 83 | } 84 | 85 | # Perform the request 86 | response = requests.post( 87 | url, 88 | files=files, 89 | headers = headers 90 | ) 91 | # Convert the JSON to Python objects 92 | if response.status_code == 200: 93 | items = response.json() 94 | return items 95 | 96 | def hash_file(file_path): 97 | # Setup buffer size and sha1 variables 98 | buff_size = 65535 99 | sha256 = hashlib.sha256() 100 | # Open the file for reading in binary 101 | with open(file_path, 'rb') as f: 102 | while True: 103 | # Read a chunk of data 104 | data = f.read(buff_size) 105 | # If we reached the end, quit while loop 106 | if not data: 107 | break 108 | # Update sha256 hash with data chunk 109 | sha256.update(data) 110 | # Return sha-256 hash 111 | return sha256.hexdigest() 112 | 113 | # Get API key from file 114 | token = get_api_key( "VirusTotal" ) 115 | api_base = "https://www.virustotal.com/api/v3" 116 | 117 | # Prompt user for file to check 118 | target_file = input( "What file do you wish to scan? " ) 119 | 120 | # Generate SHA hash 121 | print( "Generating file hash: ", end="" ) 122 | file_hash = hash_file(target_file) 123 | print(file_hash) 124 | 125 | # Check /file/report using SHA 126 | print( "Getting file report." ) 127 | vt_file_report = virustotal_get_file_report(token, file_hash) 128 | 129 | # Check if a scan has already been performed 130 | if vt_file_report: 131 | print( "File report found: " ) 132 | # get analysis stats 133 | vt_analysis_stats = vt_file_report["data"]["attributes"]["last_analysis_stats"] 134 | # malicious, suspicious, undetected 135 | print( f"\tMalicious : {vt_analysis_stats['malicious']}" ) 136 | print( f"\tSuspicious: {vt_analysis_stats['suspicious']}" ) 137 | print( f"\tUndetected: {vt_analysis_stats['undetected']}" ) 138 | 139 | # Quit script 140 | sys.exit() 141 | else: 142 | print( "No file report found, uploading for analysis." ) 143 | # Call file upload with file name 144 | upload_status = virustotal_upload_file(token, target_file) 145 | analysis_id = upload_status["data"]["id"] 146 | print( f"\tAnalysis ID: {analysis_id}" ) 147 | 148 | # Loop 3 times 149 | for i in range(3): 150 | # Wait 30 seconds 151 | print( "... sleeping for 30 seconds ..." ) 152 | time.sleep(30) 153 | # Call analysis report 154 | print( "Getting analysis report." ) 155 | analysis_results = virustotal_get_analysis(token, analysis_id) 156 | # Check analysis results 157 | if analysis_results["data"]["attributes"]["status"] == "completed": 158 | print( "Analysis complete: " ) 159 | # get analysis stats 160 | vt_analysis_stats = analysis_results["data"]["attributes"]["stats"] 161 | # malicious, suspicious, undetected 162 | print( f"\tMalicious : {vt_analysis_stats['malicious']}" ) 163 | print( f"\tSuspicious: {vt_analysis_stats['suspicious']}" ) 164 | print( f"\tUndetected: {vt_analysis_stats['undetected']}" ) 165 | 166 | # Quit script 167 | sys.exit() 168 | 169 | # attempt counter has expired, print "Try again later" 170 | print( "Scans not finished, try again in a few minutes." ) -------------------------------------------------------------------------------- /end/CH09/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "client": { 3 | "clientId": "yourcompanyname", 4 | "clientVersion": "1.5.2" 5 | }, 6 | "threatInfo": { 7 | "threatTypes": "MALWARE", 8 | "platformTypes": "LINUX", 9 | "threatEntryTypes": "URL", 10 | "threatEntries": {"url": "http://testsafebrowsing.appspot.com/s/malware.html"} 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /end/CH10/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edgoadcom/PythonforCybersecurity/1c042e0a2d03ac25933c52ec26dfd5a786c34e84/end/CH10/README.md -------------------------------------------------------------------------------- /end/CH10/flask_hello.py: -------------------------------------------------------------------------------- 1 | # First flask script 2 | # Create by Ed 11/14 3 | # Install Flask if not already installed 4 | # pip install Flask 5 | 6 | # Import modules 7 | from flask import Flask, request, render_template_string 8 | 9 | # Create main Flask object 10 | app = Flask(__name__) 11 | 12 | # Default route 13 | @app.route('/') 14 | def welcome(): 15 | return render_template_string(''' 16 | 17 | 18 |

Welcome!

19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 | ''') 27 | 28 | # Greet route 29 | @app.route('/greet', methods=['POST']) 30 | def greet(): 31 | # Retrive name from browser data 32 | name = request.form['name'] 33 | return f'

Hello {name}!

' 34 | 35 | # Run the Flask app 36 | app.run(debug=True) -------------------------------------------------------------------------------- /end/CH10/flask_mvc_space/app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Flask example that tells us how many people there are in space 3 | # By Ed Goad 4 | 5 | # Import Python modules 6 | from flask import Flask, render_template 7 | from models import get_people_in_space 8 | 9 | # Create main Flask object 10 | app = Flask(__name__) 11 | 12 | # Default route 13 | @app.route('/') 14 | def home(): 15 | return render_template('index.html') # Calls the View 16 | 17 | # get_count route 18 | @app.route('/get_count') 19 | def get_count(): 20 | number = get_people_in_space() # Calls the Model 21 | return render_template('result.html', number=number) # Calls the View 22 | 23 | # Run the Flask app 24 | if __name__ == '__main__': 25 | app.run(debug=True) 26 | -------------------------------------------------------------------------------- /end/CH10/flask_mvc_space/models.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def get_people_in_space(): 4 | """Fetches the current number of people in space from an API.""" 5 | request_uri = "http://api.open-notify.org/astros.json" 6 | response = requests.get(request_uri) 7 | 8 | if response.status_code == 200: 9 | return response.json().get("number", "Unknown") 10 | else: 11 | return "Error fetching data" 12 | -------------------------------------------------------------------------------- /end/CH10/flask_mvc_space/static/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | text-align: center; 4 | margin: 50px; 5 | background-color: #f4f4f4; 6 | } 7 | 8 | h1 { 9 | color: #333; 10 | } 11 | 12 | button { 13 | background-color: #007BFF; 14 | color: white; 15 | padding: 10px 20px; 16 | border: none; 17 | border-radius: 5px; 18 | cursor: pointer; 19 | font-size: 16px; 20 | } 21 | 22 | button:hover { 23 | background-color: #0056b3; 24 | } 25 | 26 | a { 27 | display: block; 28 | margin-top: 20px; 29 | color: #007BFF; 30 | text-decoration: none; 31 | } 32 | 33 | a:hover { 34 | text-decoration: underline; 35 | } 36 | -------------------------------------------------------------------------------- /end/CH10/flask_mvc_space/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | People in Space 5 | 6 | 7 | 8 |

Click below to get the number of people in space

9 |
10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /end/CH10/flask_mvc_space/templates/result.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | People in Space 5 | 6 | 7 | 8 |

There are {{ number }} people in space right now!

9 | Back 10 | 11 | 12 | -------------------------------------------------------------------------------- /end/CH10/geometry_managers.py: -------------------------------------------------------------------------------- 1 | # Various tkinter geometry managers 2 | # View how pack, grid, place work together 3 | # Created by Ed 11/15 4 | 5 | # Import tkinter 6 | import tkinter 7 | 8 | # Create the GUI main window 9 | my_window = tkinter.Tk() 10 | my_window.geometry('250x250') 11 | 12 | # Using pack in a separate frame 13 | frame_pack = tkinter.Frame(my_window, bg="lightblue") 14 | frame_pack.pack(side="top", fill="x") 15 | label1 = tkinter.Label(frame_pack, text="Packed Label 1") 16 | label1.pack(pady=10) 17 | label2 = tkinter.Label(frame_pack, text="Packed Label 2") 18 | label2.pack(pady=10) 19 | 20 | # Using grid in another frame 21 | frame_grid = tkinter.Frame(my_window, bg="lightgreen") 22 | frame_grid.pack(side="top", fill="x") 23 | label3 = tkinter.Label(frame_grid, text="Gridded Label 1") 24 | label3.grid(row=0, column=0, padx=10, pady=10) 25 | label4 = tkinter.Label(frame_grid, text="Gridded Label 2") 26 | label4.grid(row=1, column=1, padx=10, pady=10) 27 | 28 | # Using place in the root window 29 | label5 = tkinter.Label(my_window, text="Placed Label 1", bg="pink") 30 | label5.place(x=50, y=190) 31 | label6 = tkinter.Label(my_window, text="Placed Label 2", bg="pink") 32 | label6.place(relx=0.7, rely=0.92, anchor="center", width=100, height=30) 33 | 34 | # Enter the main event loop 35 | my_window.mainloop() 36 | -------------------------------------------------------------------------------- /end/CH10/tkinter_button.py: -------------------------------------------------------------------------------- 1 | # Seconder tkinter script 2 | # Add a button and command 3 | # Create by Ed 11/15 4 | 5 | # Import tkinter 6 | import tkinter 7 | from tkinter import messagebox 8 | 9 | # Functions 10 | def button_clicked(): 11 | tkinter.Label(my_window, text = "button was clicked").pack() 12 | messagebox.showerror("Error", "Dont click that") 13 | 14 | # Create the GUI main window 15 | my_window = tkinter.Tk() 16 | 17 | # Add widgets 18 | my_label = tkinter.Label(my_window, text = "Hello World", 19 | font = ("Arial Bold", 50)) 20 | my_label.pack() 21 | my_button = tkinter.Button(my_window, text = "Click Here", 22 | command = button_clicked) 23 | my_button.pack() 24 | 25 | # Enter the main event loop 26 | my_window.mainloop() -------------------------------------------------------------------------------- /end/CH10/tkinter_dadjokes.py: -------------------------------------------------------------------------------- 1 | # third tkinter script 2 | # Get people in space 3 | # Create by Ed 12/29 4 | 5 | # Import tkinter 6 | import tkinter 7 | from tkinter.font import Font 8 | import requests 9 | 10 | # Functions 11 | def get_dadjoke(): 12 | request_uri = "https://icanhazdadjoke.com/" 13 | headers = { "Accept": "application/json" } 14 | r = requests.get(request_uri, headers = headers) 15 | items = r.json() 16 | joke = items["joke"] 17 | my_label.configure(text = joke) 18 | 19 | # Create the GUI main window 20 | my_window = tkinter.Tk() 21 | 22 | # Create font object 23 | my_font = Font(family="Arial", weight="bold", size=50) 24 | # Set wraplength to 25 characters 25 | char_width = my_font.measure("A") 26 | wrap_length = char_width * 25 27 | 28 | # Add widgets 29 | my_label = tkinter.Label(my_window, 30 | text = "Get Dad Joke", 31 | font = my_font, 32 | wraplength=wrap_length) 33 | my_label.pack() 34 | my_button = tkinter.Button(my_window, 35 | text = "Click here to update", 36 | command = get_dadjoke) 37 | my_button.pack() 38 | 39 | # Enter the main event loop 40 | my_window.mainloop() -------------------------------------------------------------------------------- /end/CH10/tkinter_hello.py: -------------------------------------------------------------------------------- 1 | # First tkinter script 2 | # Create by Ed 11/14 3 | 4 | # Import modules 5 | import tkinter 6 | 7 | # Create the GUI main window 8 | my_window = tkinter.Tk() 9 | 10 | # Add widgets 11 | my_label = tkinter.Label(my_window, text = "Hello World", 12 | font = ("Arial Bold", 50)) 13 | my_label.pack() 14 | 15 | # Enter the main event loop 16 | my_window.mainloop() -------------------------------------------------------------------------------- /end/CH10/tkinter_label.py: -------------------------------------------------------------------------------- 1 | # Second tkinter script 2 | # Add a button and command 3 | # Create by Ed 11/15 4 | 5 | # Import tkinter 6 | import tkinter 7 | from tkinter import messagebox 8 | 9 | # Functions 10 | def button_clicked(): 11 | tkinter.Label(my_window, text = "button was clicked").pack() 12 | my_label.configure(text = "New text", 13 | font = ("Courier", 75), 14 | fg = "lightyellow", 15 | bg = "darkred" ) 16 | messagebox.showerror("Error", "Dont click that") 17 | 18 | # Create the GUI main window 19 | my_window = tkinter.Tk() 20 | 21 | # Add widgets 22 | my_label = tkinter.Label(my_window, text = "Hello World", 23 | font = ("Arial Bold", 50)) 24 | my_label.pack() 25 | my_button = tkinter.Button(my_window, text = "Click Here", 26 | command = button_clicked) 27 | my_button.pack() 28 | 29 | # Enter the main event loop 30 | my_window.mainloop() -------------------------------------------------------------------------------- /end/CH10/tkinter_peopleinspace.py: -------------------------------------------------------------------------------- 1 | # third tkinter script 2 | # Get people in space 3 | # Create by Ed 12/29 4 | 5 | # Import tkinter 6 | import tkinter 7 | import requests 8 | 9 | # Functions 10 | def get_people_in_space(): 11 | request_uri = "http://api.open-notify.org/astros.json" 12 | r = requests.get(request_uri) 13 | items = r.json() 14 | people_in_space = items["number"] 15 | tkinter.Label(my_window, text = people_in_space).pack() 16 | 17 | # Create the GUI main window 18 | my_window = tkinter.Tk() 19 | 20 | # Add widgets 21 | my_label = tkinter.Label(my_window, text = "People in Space", 22 | font = ("Arial Bold", 50)) 23 | my_label.pack() 24 | my_button = tkinter.Button(my_window, text = "Click here to update", 25 | command = get_people_in_space) 26 | my_button.pack() 27 | 28 | # Enter the main event loop 29 | my_window.mainloop() -------------------------------------------------------------------------------- /end/CH11/answer_questions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that connects to HuggingFace and performs a query 3 | # Requires an API key to run - https://huggingface.co/settings/tokens 4 | # By Ed Goad 5 | # date: 1/3 6 | 7 | # Import Python modules 8 | import requests 9 | import configparser 10 | import os 11 | 12 | def get_api_key(key_name): 13 | # Get the location of the secrets file 14 | home_dir = os.path.expanduser("~") 15 | secrets_file = os.path.join(home_dir, "secrets.ini") 16 | # Create the ConfigParser and load the file 17 | config = configparser.ConfigParser() 18 | config.read(secrets_file) 19 | # Get the API key and return 20 | api_key = config["APIKeys"][key_name] 21 | return api_key 22 | 23 | def get_ai_response(prompt, api_key): 24 | # Build the URI to the API 25 | base_uri = "https://api-inference.huggingface.co/models/" 26 | model = "mistralai/Mistral-Nemo-Instruct-2407" 27 | request_uri = base_uri + model + "/v1/chat/completions" 28 | 29 | request_headers = { 30 | 'Authorization': 'Bearer '+ api_key, 31 | 'Content-Type': 'application/json', 32 | } 33 | payload = { 34 | "model": model, 35 | "messages": [ 36 | { 37 | "role": "user", 38 | "content": prompt 39 | } 40 | ] 41 | } 42 | r = requests.post( 43 | request_uri, 44 | headers = request_headers, 45 | json = payload 46 | ) 47 | 48 | if r.status_code == 200: 49 | result = r.json() 50 | return result 51 | 52 | # Define assumptions to go along with the questions 53 | assumptions = [ 54 | "I am a teacher.", 55 | "This is for an elementary school.", 56 | "Responses should be simple and easy to understand." 57 | ] 58 | 59 | # Get API key 60 | api_key = get_api_key("huggingface") 61 | 62 | # Ask the user for a prompt 63 | question = input("Enter your question: ") 64 | 65 | # Join the assumptions and question, and send to API 66 | prompt = "\n".join(assumptions) + f"\n\nQuestion: {question}\nAnswer:" 67 | responses = get_ai_response(prompt, api_key) 68 | 69 | # Print responses 70 | for response in responses["choices"]: 71 | print(response["message"]["content"]) -------------------------------------------------------------------------------- /end/CH11/create_image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that connects to HuggingFace and performs a query 3 | # Requires an API key to run - https://huggingface.co/settings/tokens 4 | # By Ed Goad 5 | # date: 1/3 6 | 7 | # Import Python modules 8 | import requests 9 | import configparser 10 | import os 11 | 12 | def get_api_key(key_name): 13 | # Get the location of the secrets file 14 | home_dir = os.path.expanduser("~") 15 | secrets_file = os.path.join(home_dir, "secrets.ini") 16 | # Create the ConfigParser and load the file 17 | config = configparser.ConfigParser() 18 | config.read(secrets_file) 19 | # Get the API key and return 20 | api_key = config["APIKeys"][key_name] 21 | return api_key 22 | 23 | def generate_image(prompt, api_key): 24 | # Build URI to API 25 | base_uri = "https://api-inference.huggingface.co/models/" 26 | model = "black-forest-labs/FLUX.1-dev" 27 | request_uri = base_uri + model 28 | request_headers = { 29 | 'Authorization': 'Bearer '+ api_key, 30 | 'Content-Type': 'application/json', 31 | } 32 | payload = { 33 | "inputs": prompt 34 | } 35 | r = requests.post( 36 | request_uri, 37 | headers = request_headers, 38 | json = payload 39 | ) 40 | 41 | if r.status_code == 200: 42 | return r.content 43 | 44 | # Ask the user for a prompt 45 | prompt = input("Enter a prompt for the image generation (e.g., 'a cat on a beach'): ") 46 | 47 | # Get API key 48 | api_key = get_api_key("huggingface") 49 | 50 | # Generate the image from text 51 | image_bytes = generate_image(prompt, api_key) 52 | 53 | # Save image to file 54 | with open('downloaded_image.jpg', 'wb') as f: 55 | f.write(image_bytes) -------------------------------------------------------------------------------- /start/CH01/README.md: -------------------------------------------------------------------------------- 1 | # Intro to Linux environment 2 | Brief introduction to Raspberry Pi 3 | - Why it was invented 4 | - benefits of Linux 5 | - some simple commands + links to finding more 6 | 7 | # Workign with github 8 | Create GitHub Account 9 | Use `git clone` to download/sync to linux 10 | Commands to push/pull 11 | ``` 12 | git pull 13 | git add . 14 | git commit -m "comment here" 15 | git push 16 | ``` 17 | github publish script 18 | 19 | ## Optionally 20 | - using .gitignore 21 | - other ways to store passwords 22 | 23 | # Intro to python - no scripting, just talk about it 24 | Benefits of python 25 | Where python is used 26 | Interpreted vs compiled language 27 | -------------------------------------------------------------------------------- /start/CH02/HelloWorld.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple "Hello World" script in python 3 | # Created -------------------------------------------------------------------------------- /start/CH02/HelloWorld2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple "Hello World" script in python with Inputs 3 | # Created 4 | 5 | # Suggestion, build out 1 line at a time 6 | # Once multiple print statemetns exist, put a breakpoint at first print line 7 | # Then walk through as an example of "debugging" 8 | -------------------------------------------------------------------------------- /start/CH02/HelloWorld3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A more complex "Hello World" script in python with Inputs 3 | # Created 4 | -------------------------------------------------------------------------------- /start/CH02/README.md: -------------------------------------------------------------------------------- 1 | # Starting with python3 2 | - interactive python 3 | ``` 4 | python3 5 | 20 + 32 6 | 15 - 7 7 | 7 * 7 8 | 2 ** 8 9 | print("Hello There") 10 | ``` 11 | - variables: variable is a box, whats in it what you put there 12 | ``` 13 | message = "Hello There" 14 | print(message) 15 | n = 17 16 | pi = 3.1415926535 17 | print(n + pi) 18 | ``` 19 | - data types 20 | ``` 21 | type(message) 22 | type(n) 23 | type(pi) 24 | ``` 25 | # Starting with an IDE 26 | - Installing VSCode 27 | - Syncronizing with GitHub 28 | 29 | 30 | # creating first few scripts 31 | ### HelloWorld.py 32 | - Commit to Github 33 | - Running in IDE and command line 34 | 35 | ### HelloWorld2.py 36 | - Commit and run with simple input/print 37 | - Different ways to print the hello statement (add all then run) 38 | 39 | # Use IDE debugger 40 | - Using HelloWorld2.py 41 | - stop at first print statement and step through code -------------------------------------------------------------------------------- /start/CH02/SimpleCalculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # A simple calculator to show math and conditionals 3 | # Created 4 | -------------------------------------------------------------------------------- /start/CH03/Conditionals.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with conditionals 3 | #By -------------------------------------------------------------------------------- /start/CH03/Funcy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with Functions 3 | #By -------------------------------------------------------------------------------- /start/CH03/Loopy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # example workign with Loops 3 | #By -------------------------------------------------------------------------------- /start/CH03/README.md: -------------------------------------------------------------------------------- 1 | # Its ok if this flows into next week 2 | 3 | # Ping 4 | Starting with simple ping script / interactive mode 5 | ``` 6 | import platform 7 | import os 8 | pingCMD = f"ping -c 1 -w 2 {ip} > /dev/null 2>&1" 9 | os.system(pingCMD) 10 | ``` 11 | 12 | # Conditionals 13 | Show how conditionals work (if, elif, else) and evaluations (<>=) 14 | - Build out conditionals.py without function 1 evaluation at a time 15 | - Debug if necessary 16 | Add in conditionals to accomidate Windows or Linux 17 | - Try command on a Windows machine to see how it works differntly? 18 | - save as pinger1.py 19 | - use debugger to walk through it 20 | 21 | # Loops 22 | Show how loops work 23 | - simple FOR loop `for x in range(6):` 24 | - If time later, come back to more loop types 25 | Add in loop to loop through multiple IPs 26 | - start with simple print statement to show how to loop and how it will work 27 | - use debugger to walk through 28 | ``` 29 | startIP = "192.168.0." 30 | for x in range(254): 31 | ip = startIP + str(x + 1) 32 | print(ip) 33 | ``` 34 | - extend pinger1.py into pinger2.py 35 | - use debugger if necessary 36 | 37 | # Functions 38 | Show how functions work 39 | - reusable code 40 | - send input 41 | - receive output 42 | Move ping command into function 43 | - receive IP as input, return exit_code 44 | - save as pinger3.py 45 | - debug if necessary 46 | 47 | -------------------------------------------------------------------------------- /start/CH03/deleteme.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edgoadcom/PythonforCybersecurity/1c042e0a2d03ac25933c52ec26dfd5a786c34e84/start/CH03/deleteme.py -------------------------------------------------------------------------------- /start/CH03/pinger1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # First example of pinging from Python 3 | # By -------------------------------------------------------------------------------- /start/CH03/pinger2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Second example of pinging from Python 3 | # By -------------------------------------------------------------------------------- /start/CH03/pinger3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Third example of pinging from Python 3 | # By -------------------------------------------------------------------------------- /start/CH03/pinger4.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fourth example of pinging from Python 3 | # By -------------------------------------------------------------------------------- /start/CH04/README.md: -------------------------------------------------------------------------------- 1 | # Reading Files 2 | create a file named **testfile.txt** and show how to read it 3 | readFile.py 4 | 5 | Create a new file **ips.txt** and use it as input for loop (put whatever IPs desired) 6 | pinger4.py 7 | 8 | If time exists, put bad data in ips.txt and show how important it is to validate input 9 | 10 | # Writing Files 11 | show how to write a file 12 | writeFile.py 13 | 14 | Create function to write to a log 15 | pinger5.py 16 | Extend log by adding date/time 17 | - google how to get date/time for python -------------------------------------------------------------------------------- /start/CH04/ReadFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sample script that reads from a file 3 | # By -------------------------------------------------------------------------------- /start/CH04/ScannerExample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Port scanner example 3 | # Use 'pip3 install python-nmap' to install modules 4 | # Use 'sudo apt -y install nmap' to install nmapccc 5 | # By -------------------------------------------------------------------------------- /start/CH04/WriteFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sample script that writes to a file 3 | # By -------------------------------------------------------------------------------- /start/CH04/ips.txt: -------------------------------------------------------------------------------- 1 | 192.168.0.10 2 | 192.168.0.11 3 | 192.168.0.12 4 | 192.168.0.13 5 | 192.168.0.14 6 | 192.168.0.15 7 | 192.168.0.16 8 | 192.168.0.17 9 | 192.168.0.18 10 | 192.168.0.19 11 | 192.168.0.110 12 | 192.168.0.111 13 | 192.168.0.112 14 | 192.168.0.113 15 | 192.168.0.114 16 | 192.168.0.115 -------------------------------------------------------------------------------- /start/CH04/pinger5.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Fifth example of pinging from Python 3 | # Reading IPs from a file 4 | # By -------------------------------------------------------------------------------- /start/CH04/pinger6.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Sixth example of pinging from Python 3 | # Writing log messages to a file 4 | # By -------------------------------------------------------------------------------- /start/CH05/ASCIIgen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # ASCII generator 3 | # Uses chr() to create ASCII characters 4 | # By -------------------------------------------------------------------------------- /start/CH05/Base64.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that "encrypts"/"decrypts" text using base64 encoding 3 | # By -------------------------------------------------------------------------------- /start/CH05/CryptExample.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that encrypts/decrypts text using cryptography module 3 | # By -------------------------------------------------------------------------------- /start/CH05/README.md: -------------------------------------------------------------------------------- 1 | # Intro to cryptography 2 | 3 | # How cryptography *can work* - ROT13 4 | Introduce the idea of ROT13 5 | - **Hello World** --> **Uryyb Jbeyq** --> **Hello World** 6 | - https://en.wikipedia.org/wiki/ROT13 7 | - simple-ish to program because 13 + 13 = 26 --> 26 letters 8 | 9 | Introduct the ASCII table http://www.asciitable.com/ 10 | - highlight the fact that letters are numbers 11 | - Using interactive mode, show the **ord()** and **chr()** commands 12 | 13 | Start building **rot13.py** 14 | - Manually walk through converting **abc** --> **97 98 99** --> **110 111 112** --> **nop** 15 | - Use a for loop to access each letter individually. *Another way to use a for loop* 16 | - easy to start, but highlight issues as they occur 17 | - for ease, force everythign to be lower case 18 | - Figure out how to deal with non-letters (such as spaces) 19 | - make encrypt/decrypt process a function 20 | 21 | If time allows, use **base64.py** as example of more complex processing 22 | 23 | # WARNING - Dont create your own encryption scheme! 24 | rot13 is simple to understand, and can be easily expanded to rotx.py or encrypting files 25 | Unless you are a full time security researcher, dont "roll-your-own" encryption scheme, 26 | use the predefined encryption modules. What is hard for you, coudl be easy for someone else. 27 | 28 | The goal of cryptography is that the crypto process should be commonly known. What should 29 | be secret is the encryption keys. That way everyone can provide input on the best scheme 30 | to use, resulting in a better and more secure encryption process 31 | 32 | # Legit cryptography 33 | Highlight https://pypi.org/ as a repository of Python packages/libraris/dlls 34 | There are 2 programs, **pip** and **pip3**. In general pip3 is for Python3 35 | NOTE: For the cryptography library, you may need to use one of the following commands to install the cryptography module: 36 | ``` 37 | pip3 install cryptography 38 | ``` 39 | Fernet is a type of *symmetric cryptography* - same key to encrypt and decrypt 40 | Unlike ROT13, there are different processes to encrypt and decrypt 41 | 42 | ## start in interactive mode 43 | ### generate key 44 | ``` 45 | from cryptography.fernet import Fernet 46 | Fernet.generate_key() 47 | ``` 48 | Note the case sensitivity and the **b** before the output 49 | The **b** refers to bytes, this is easier for the computer to handle. 50 | Do a `print(type(key))` and `print(type(key.decode()))` to confirm 51 | to remove the **b**, we **decode** it 52 | ``` 53 | key = Fernet.generate_key() # store in a secure location 54 | print("Key:", key.decode()) 55 | ``` 56 | ### encrypt data 57 | ``` 58 | plainText = "Hello There" 59 | plainText = plainText.encode() 60 | cipherText = Fernet(key).encrypt(plainText) 61 | cipherText = cipherText.decode() 62 | print(cipherText) 63 | ``` 64 | ### decrypt data 65 | ``` 66 | cipherText = cipherText.encode() 67 | key = key.encode() 68 | plainText = Fernet(key).decrypt(cipherText) 69 | plainText = plainText.decode() 70 | ``` 71 | 72 | 73 | 74 | 75 | 76 | 77 | # Lots of encryption examples online 78 | https://cryptography.io/en/latest/fernet.html 79 | https://www.geeksforgeeks.org/fernet-symmetric-encryption-using-cryptography-module-in-python/ 80 | https://devqa.io/encrypt-decrypt-data-python/ 81 | https://www.programcreek.com/python/example/98805/cryptography.fernet.Fernet 82 | https://docs.python-guide.org/scenarios/crypto/ 83 | 84 | -------------------------------------------------------------------------------- /start/CH05/Rot13.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that encrypts/decrypts text using ROT13 3 | # By -------------------------------------------------------------------------------- /start/CH06/CreateHash1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password 3 | # By -------------------------------------------------------------------------------- /start/CH06/CreateHash2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password with provided salt 3 | # By -------------------------------------------------------------------------------- /start/CH06/README.md: -------------------------------------------------------------------------------- 1 | # Hacking linux passwords 2 | Linux passwords are stored in the file /etc/shadow, which is only readable by root. This restriction is added because if you can read the passwords, you can hack the passwords. 3 | These arent the passwords, but hashes of the passwords. Hashing is similar to encryption, but is a one-way process and can't be unencrypted. This means the actual password cant be retrieved from the hash 4 | We can however **guess** at the contents, and then hash them to see if they match 5 | 6 | # Breakdown of /etc/shadow 7 | Sample line from /etc/shadow. Username **justincase**, password **Password01** 8 | `justincase:$6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.:18617:0:99999:7:::` 9 | 10 | The password hash is between 1st and 2nd colons (`$6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.` in the example above) 11 | The password hash is made up of: 12 | 1. the first few characters define the hashing algorithm: (`$6` in the example above) 13 | - $1=MD5 14 | - $2=Blowfish 15 | - $2a=eksblowfish 16 | - $5=SHA-256 17 | - $6=SHA-512 18 | 2. A SALT which is between the 2 dollar signs (`G.DTW7g9s5U7KYf5` in the example above) 19 | - Note: the SALT is random and is used to complicate the HASH 20 | - This ensures if 2 passwords are the same, the HASH is different 21 | 3. The hash of the salted password (`xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p.`) 22 | 23 | # Creating password hashes 24 | Uses **crypt** module. NOTE: this is a Linux module and may not work on other operating systems. There are similar modules for Windows, search Google for the best option. 25 | Possibly start in interactive mode. Show without / with SALT 26 | ``` 27 | import crypt 28 | print(crypt.crypt("Password01") 29 | print(crypt.crypt("Password01", "$6$G.DTW7g9s5U7KYf5$") 30 | ``` 31 | Use **passHasher.py** to show different encryption methods (not all are available) 32 | Demonstrate how the SALT changes the HASH 33 | If same password and salt are used, resultant HASH is the same -- this is how passwords work 34 | 35 | # Guessing passwords 36 | Create script that prompts for: 37 | 1. Hashed password from /etc/shadow 38 | 2. The SALT to use 39 | 3. Plaintext password 40 | 41 | Create a function called **testPass** that hashes the plaintext password with the salt and compares with the hashedPass 42 | If the hashes match, return **True**, else return **False** 43 | 44 | # Dictionary attack 45 | Extend guessing script to include 46 | - Reading plaintext password from a file 47 | - 1 at a time, tries the passwords 48 | - When a match is found, program quits and reports the correct password 49 | 50 | **NOTE:** For testing you may want to limit the dictionary file to ~10 passwords and use #5 as the hashed password 51 | Most common passwords pulled from https://github.com/danielmiessler/SecLists/tree/master/Passwords/Common-Credentials 52 | 53 | # Brute Force attack 54 | Example of how a brute force attack works. See image of bike combo lock with 4 numbers, each ranging 0-9 55 | ![](https://thebestbikelock.com/wp-content/uploads/2019/10/combination-lock.jpg) 56 | 57 | To brute force this, you start at `0000`, then `0001`, and so on until you reach `9999` or the correct answer 58 | If you dont know the length of the password, you start at `0` and keep going until `9999999999999` 59 | 60 | This example is similar to the Dictionary attack and uses same **testPass** function.Instead of reading from a file, we do a `for i in range(100000)` 61 | This example is simplified to only numbers. Use debugger if needed to highlight how each number in turn is being tested. 62 | 63 | More complex brute forcing includes larger character sets such as those shown below. This obviously complicates and slows the process, explaining why this may be the last choice in an attack 64 | - abcdefghijklmnopqrstuvwxyz 65 | - ABCDEFGHIJKLMNOPQRSTUVWXYZ 66 | - 0123456789 67 | - 0123456789abcdef 68 | - 0123456789ABCDEF 69 | - «space»!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 70 | - ?l?u?d?s 71 | - 0x00 - 0xff 72 | 73 | 74 | # Other suggestions 75 | Have students create process that separates hashed password into SALT and HASH so that it is no longer prompted 76 | Have students create script that opens a shadow file and pulls out the hashes for attacking 77 | -------------------------------------------------------------------------------- /start/CH06/bruteforceAttack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Example brute-force attacker 3 | #By Ed Goad 4 | # date: 2/5/2021 5 | 6 | # NOTE: this example is limited to numbers. There are no letters or symbols in this example 7 | # Suggested to start by debugging to show how brute force walks through all available options 8 | 9 | 10 | hashed_password = "$6$G.DTW7g9s5U7KYf5$QFcHx0/J88HV/Q0ab653gfYQ1KyNGx5HRhDQYyai2ZUy7Aw4tyfJ6/kI6kllfXl0DyS.LuaUJvqnlIn2fVM5F0" 11 | algorithm_salt = "$6$G.DTW7g9s5U7KYf5$" 12 | -------------------------------------------------------------------------------- /start/CH06/dictionaryAttack.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that performs a dictionary attack against known password hashes 3 | # Needs a dictionary file, suggested to use https://github.com/danielmiessler/SecLists/tree/master/Passwords/Common-Credentials 4 | # By -------------------------------------------------------------------------------- /start/CH06/passHasher.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that hashes a password 3 | #By 4 | 5 | # Sample data 6 | # Password: Password01 7 | # Salt: G.DTW7g9s5U7KYf5 8 | # SHA-512 result: $6$G.DTW7g9s5U7KYf5$xTXAbS1Q30hfd10VDbkSh5adZMxbqRUMOyNyKopfFpMvD.Vf/CcoEBn/TUYcfJ1jAaEiJPBf/PoCLFq7U7Q7p. 9 | -------------------------------------------------------------------------------- /start/CH06/shadow: -------------------------------------------------------------------------------- 1 | root:!:18830:0:99999:7::: 2 | daemon:*:18667:0:99999:7::: 3 | bin:*:18667:0:99999:7::: 4 | sys:*:18667:0:99999:7::: 5 | backup:*:18667:0:99999:7::: 6 | list:*:18667:0:99999:7::: 7 | irc:*:18667:0:99999:7::: 8 | gnats:*:18667:0:99999:7::: 9 | nobody:*:18667:0:99999:7::: 10 | gdm:*:18667:0:99999:7::: 11 | systemd-coredump:!!:18830:::::: 12 | hackme01:$6$ruzSF91zH9x9MeX6$WWWJ/9Is89yhYhGi.gCtTAePPIndPO8tf0Ux6NDs6QHfiTh//En9ftlpB5w9hYCxShv23YhmSruCwn4HP6xrU0:18886:0:99999:7::: 13 | hackme02:$6$O9OcwTwNbVKqK24q$FuVUpZsHC5uLLBSxUKYYpu6NzuSo/6tkmAyet8XyUsDy9g8v7WkEXbl4Rj6MW45xjl9Hyn15OGUdOPdkfJvVS.:18886:0:99999:7::: 14 | hackme03:$6$hqNeQoE5XBvDfEVk$OOJ0RWHMkG2PagKZukgA/swcQETLvGuoErUGkCEoLe3v7xZS6Fzc7nbIfXL1pdgk9jJNqyEOvsVUdNTblYjGy0:18886:0:99999:7::: 15 | hackme04:$6$ch8Vehhld0VzFI6y$6ccEIQVHGD7JE/Rskr12TSeNepKhejyub9g67BTM06ZHxQj1qJu9QDj0HiEM/d/03qgXU3i34sc4tFxz..Vln0:18886:0:99999:7::: 16 | hackme05:$6$/SODHa2dtiVj2hPK$VkNteUOBL6dg6ZbtkB3lZzlCJNR2i.eZF0yXxfh8Q1VsT6UzQ4/XVzHpy90snNR/4Ni4i55FrBgrLw3yI2aL60:18886:0:99999:7::: 17 | hackme06:$6$Zo9jq1UXAuEREPgV$LO8roNOpumamxda1TQ6TZcY.t5LF3cypAMboqWfQ1EokC.RcKnYERfrqzR5kkAKI4/TE6ysu6RkKEdwrz6pfS/:18886:0:99999:7::: 18 | hackme07:$6$9mxNwV65ywcAMSx3$.UOKPDgsj50EfJYajcQ4KBGgIEyY3QpkgKOvtNWMFq86xJLJ3KneiQD6pZMamXcVxtyvPEQjMvSF.nHI3Yj.T/:18886:0:99999:7::: 19 | hackme08:$6$6c/xO/skqVsSZgIA$0Avu1xnlg/nr5pcLF5CujYTlbmixkiAbFSITC/lqOkKmNZsh4zGeQml1Bfx58dgxPMI3g0BjyGT4FinTKf3JO.:18886:0:99999:7::: 20 | hackme09:$6$wjQCpm0A2rkutLJN$vF7GcHfuFBdb2E4t9XaGOytR5rW43nIhUcpErzpWKFV6q7T9QMMXs6iJZyWohTSffcMncyZaOUzyT7wKGdi5M1:18886:0:99999:7::: 21 | hackme10:$6$m96VAMjtUMd8qtSm$ilet44..E0ZYLkPEkVeewpMjQSa0Tl8Uy1scEJLNch1DA4sZ3nsCuSFP0YBttGOnwbX5ySJoTjixHZgGSQfDB/:18886:0:99999:7::: 22 | hackme11:$6$wlJ7egutqr6ZqZh3$sMp2f2DjDKnyS6nDRSNOY3sfeMPZfbK73.eqe03CvqbTZ79e8bR9cUJCojCOHQKwxzbdCahplHzB8FZhNgn6T/:18886:0:99999:7::: 23 | hackme12:$6$u3Ny9M9DbSLqRBkI$r1IVUrGJj2/5WyDhi4KWB9NJ9uorTvX8a7aTzWI9rPdgRHKcMkLTT0Cuz3dSsq.WzmTvpA5Nswoy.2mrmILJX.:18886:0:99999:7::: 24 | hackme13:$6$DSBiJzN/zdd3.G3c$WR5STYPORyo9lzuoHdchRenZ2CSMMU6tv4JQcZS1crEOOy8Q4YUPEWF6BZcio94UC1wE37JnYzlAQBUdpRAjb0:18886:0:99999:7::: 25 | hackme14:$6$5hmepsiG9GimaTq8$nNZGCVj7MGF/6gDcYwxOu1ZzKQpzpbimn6Mwl1Wcb3otJi61Vbfcf9X674a6srUQbZMR4wGlrYg8afMauaZLP1:18886:0:99999:7::: 26 | hackme15:$6$AdG35bS8xEbKnc/V$UMoj8lcgtviIpbwGpeHbqG5vrdmAs.Nv4wFsqyv2fvQlW2O.g0oNtO77zSISMP8GS4FqzgRCjaUxxYxTl2Ly2/:18886:0:99999:7::: 27 | hackme16:$6$PfBwY10JPwvdEprh$mcJ1AVJXqRiXnhcap8toF2HCUPDz5gnNobQ8UTk.UkBP7XFe00NeV.cRylUlKWuEPOB4y9VktUJiTeftX0oL7.:18886:0:99999:7::: 28 | hackme17:$6$GI2cH8zAmWH.3wNl$sxqPYl8Nd2C0fJeD6NN4DwV7UhL/4bnp.rZLOKq24f8nl4fUmzbhYH.QOkXxZHmt35GyG9TYNacj4REK2LYB/.:18886:0:99999:7::: 29 | hackme18:$6$9jRhBbxUBQKFpgRY$L3PIQcXtba1.A3vpm10l2/phsUBcYkcitJUQPltF/TXh11BJMxIfRsPYJkR8DunInaukO7nFD084NEyNc8Ut41:18886:0:99999:7::: 30 | hackme19:$6$Yy2AVSdSGxefRjep$nB2tF.MMpl6/oJAayuLdOWFYyhjyeu7CRE5v6/OjW2Y91pd540SqXsTtzProS.U4CSDM2K24.VQwuLU5xRLEU/:18886:0:99999:7::: 31 | hackme20:$6$wZ0.Jc/vbgQNMuF3$gbKUkWvvvR/lOmtATn3N9wPHERkWqIqOd9pJVGS3zHcZ64P9oekEoT89x1wXRaw8hSb78SFQK2mfNYjVyaC6P0:18886:0:99999:7::: 32 | -------------------------------------------------------------------------------- /start/CH06/top10.txt: -------------------------------------------------------------------------------- 1 | 123456 2 | password 3 | 12345678 4 | qwerty 5 | 123456789 6 | 12345 7 | 1234 8 | 111111 9 | 1234567 10 | dragon 11 | -------------------------------------------------------------------------------- /start/CH06/top1000.txt: -------------------------------------------------------------------------------- 1 | 123456 2 | password 3 | 12345678 4 | qwerty 5 | 123456789 6 | 12345 7 | 1234 8 | 111111 9 | 1234567 10 | dragon 11 | 123123 12 | baseball 13 | abc123 14 | football 15 | monkey 16 | letmein 17 | 696969 18 | shadow 19 | master 20 | 666666 21 | qwertyuiop 22 | 123321 23 | mustang 24 | 1234567890 25 | michael 26 | 654321 27 | pussy 28 | superman 29 | 1qaz2wsx 30 | 7777777 31 | fuckyou 32 | 121212 33 | 000000 34 | qazwsx 35 | 123qwe 36 | killer 37 | trustno1 38 | jordan 39 | jennifer 40 | zxcvbnm 41 | asdfgh 42 | hunter 43 | buster 44 | soccer 45 | harley 46 | batman 47 | andrew 48 | tigger 49 | sunshine 50 | iloveyou 51 | fuckme 52 | 2000 53 | charlie 54 | robert 55 | thomas 56 | hockey 57 | ranger 58 | daniel 59 | starwars 60 | klaster 61 | 112233 62 | george 63 | asshole 64 | computer 65 | michelle 66 | jessica 67 | pepper 68 | 1111 69 | zxcvbn 70 | 555555 71 | 11111111 72 | 131313 73 | freedom 74 | 777777 75 | pass 76 | fuck 77 | maggie 78 | 159753 79 | aaaaaa 80 | ginger 81 | princess 82 | joshua 83 | cheese 84 | amanda 85 | summer 86 | love 87 | ashley 88 | 6969 89 | nicole 90 | chelsea 91 | biteme 92 | matthew 93 | access 94 | yankees 95 | 987654321 96 | dallas 97 | austin 98 | thunder 99 | taylor 100 | matrix 101 | william 102 | corvette 103 | hello 104 | martin 105 | heather 106 | secret 107 | fucker 108 | merlin 109 | diamond 110 | 1234qwer 111 | gfhjkm 112 | hammer 113 | silver 114 | 222222 115 | 88888888 116 | anthony 117 | justin 118 | test 119 | bailey 120 | q1w2e3r4t5 121 | patrick 122 | internet 123 | scooter 124 | orange 125 | 11111 126 | golfer 127 | cookie 128 | richard 129 | samantha 130 | bigdog 131 | guitar 132 | jackson 133 | whatever 134 | mickey 135 | chicken 136 | sparky 137 | snoopy 138 | maverick 139 | phoenix 140 | camaro 141 | sexy 142 | peanut 143 | morgan 144 | welcome 145 | falcon 146 | cowboy 147 | ferrari 148 | samsung 149 | andrea 150 | smokey 151 | steelers 152 | joseph 153 | mercedes 154 | dakota 155 | arsenal 156 | eagles 157 | melissa 158 | boomer 159 | booboo 160 | spider 161 | nascar 162 | monster 163 | tigers 164 | yellow 165 | xxxxxx 166 | 123123123 167 | gateway 168 | marina 169 | diablo 170 | bulldog 171 | qwer1234 172 | compaq 173 | purple 174 | hardcore 175 | banana 176 | junior 177 | hannah 178 | 123654 179 | porsche 180 | lakers 181 | iceman 182 | money 183 | cowboys 184 | 987654 185 | london 186 | tennis 187 | 999999 188 | ncc1701 189 | coffee 190 | scooby 191 | 0000 192 | miller 193 | boston 194 | q1w2e3r4 195 | fuckoff 196 | brandon 197 | yamaha 198 | chester 199 | mother 200 | forever 201 | johnny 202 | edward 203 | 333333 204 | oliver 205 | redsox 206 | player 207 | nikita 208 | knight 209 | fender 210 | barney 211 | midnight 212 | please 213 | brandy 214 | chicago 215 | badboy 216 | iwantu 217 | slayer 218 | rangers 219 | charles 220 | angel 221 | flower 222 | bigdaddy 223 | rabbit 224 | wizard 225 | bigdick 226 | jasper 227 | enter 228 | rachel 229 | chris 230 | steven 231 | winner 232 | adidas 233 | victoria 234 | natasha 235 | 1q2w3e4r 236 | jasmine 237 | winter 238 | prince 239 | panties 240 | marine 241 | ghbdtn 242 | fishing 243 | cocacola 244 | casper 245 | james 246 | 232323 247 | raiders 248 | 888888 249 | marlboro 250 | gandalf 251 | asdfasdf 252 | crystal 253 | 87654321 254 | 12344321 255 | sexsex 256 | golden 257 | blowme 258 | bigtits 259 | 8675309 260 | panther 261 | lauren 262 | angela 263 | bitch 264 | spanky 265 | thx1138 266 | angels 267 | madison 268 | winston 269 | shannon 270 | mike 271 | toyota 272 | blowjob 273 | jordan23 274 | canada 275 | sophie 276 | Password 277 | apples 278 | dick 279 | tiger 280 | razz 281 | 123abc 282 | pokemon 283 | qazxsw 284 | 55555 285 | qwaszx 286 | muffin 287 | johnson 288 | murphy 289 | cooper 290 | jonathan 291 | liverpoo 292 | david 293 | danielle 294 | 159357 295 | jackie 296 | 1990 297 | 123456a 298 | 789456 299 | turtle 300 | horny 301 | abcd1234 302 | scorpion 303 | qazwsxedc 304 | 101010 305 | butter 306 | carlos 307 | password1 308 | dennis 309 | slipknot 310 | qwerty123 311 | booger 312 | asdf 313 | 1991 314 | black 315 | startrek 316 | 12341234 317 | cameron 318 | newyork 319 | rainbow 320 | nathan 321 | john 322 | 1992 323 | rocket 324 | viking 325 | redskins 326 | butthead 327 | asdfghjkl 328 | 1212 329 | sierra 330 | peaches 331 | gemini 332 | doctor 333 | wilson 334 | sandra 335 | helpme 336 | qwertyui 337 | victor 338 | florida 339 | dolphin 340 | pookie 341 | captain 342 | tucker 343 | blue 344 | liverpool 345 | theman 346 | bandit 347 | dolphins 348 | maddog 349 | packers 350 | jaguar 351 | lovers 352 | nicholas 353 | united 354 | tiffany 355 | maxwell 356 | zzzzzz 357 | nirvana 358 | jeremy 359 | suckit 360 | stupid 361 | porn 362 | monica 363 | elephant 364 | giants 365 | jackass 366 | hotdog 367 | rosebud 368 | success 369 | debbie 370 | mountain 371 | 444444 372 | xxxxxxxx 373 | warrior 374 | 1q2w3e4r5t 375 | q1w2e3 376 | 123456q 377 | albert 378 | metallic 379 | lucky 380 | azerty 381 | 7777 382 | shithead 383 | alex 384 | bond007 385 | alexis 386 | 1111111 387 | samson 388 | 5150 389 | willie 390 | scorpio 391 | bonnie 392 | gators 393 | benjamin 394 | voodoo 395 | driver 396 | dexter 397 | 2112 398 | jason 399 | calvin 400 | freddy 401 | 212121 402 | creative 403 | 12345a 404 | sydney 405 | rush2112 406 | 1989 407 | asdfghjk 408 | red123 409 | bubba 410 | 4815162342 411 | passw0rd 412 | trouble 413 | gunner 414 | happy 415 | fucking 416 | gordon 417 | legend 418 | jessie 419 | stella 420 | qwert 421 | eminem 422 | arthur 423 | apple 424 | nissan 425 | bullshit 426 | bear 427 | america 428 | 1qazxsw2 429 | nothing 430 | parker 431 | 4444 432 | rebecca 433 | qweqwe 434 | garfield 435 | 01012011 436 | beavis 437 | 69696969 438 | jack 439 | asdasd 440 | december 441 | 2222 442 | 102030 443 | 252525 444 | 11223344 445 | magic 446 | apollo 447 | skippy 448 | 315475 449 | girls 450 | kitten 451 | golf 452 | copper 453 | braves 454 | shelby 455 | godzilla 456 | beaver 457 | fred 458 | tomcat 459 | august 460 | buddy 461 | airborne 462 | 1993 463 | 1988 464 | lifehack 465 | qqqqqq 466 | brooklyn 467 | animal 468 | platinum 469 | phantom 470 | online 471 | xavier 472 | darkness 473 | blink182 474 | power 475 | fish 476 | green 477 | 789456123 478 | voyager 479 | police 480 | travis 481 | 12qwaszx 482 | heaven 483 | snowball 484 | lover 485 | abcdef 486 | 00000 487 | pakistan 488 | 007007 489 | walter 490 | playboy 491 | blazer 492 | cricket 493 | sniper 494 | hooters 495 | donkey 496 | willow 497 | loveme 498 | saturn 499 | therock 500 | redwings 501 | bigboy 502 | pumpkin 503 | trinity 504 | williams 505 | tits 506 | nintendo 507 | digital 508 | destiny 509 | topgun 510 | runner 511 | marvin 512 | guinness 513 | chance 514 | bubbles 515 | testing 516 | fire 517 | november 518 | minecraft 519 | asdf1234 520 | lasvegas 521 | sergey 522 | broncos 523 | cartman 524 | private 525 | celtic 526 | birdie 527 | little 528 | cassie 529 | babygirl 530 | donald 531 | beatles 532 | 1313 533 | dickhead 534 | family 535 | 12121212 536 | school 537 | louise 538 | gabriel 539 | eclipse 540 | fluffy 541 | 147258369 542 | lol123 543 | explorer 544 | beer 545 | nelson 546 | flyers 547 | spencer 548 | scott 549 | lovely 550 | gibson 551 | doggie 552 | cherry 553 | andrey 554 | snickers 555 | buffalo 556 | pantera 557 | metallica 558 | member 559 | carter 560 | qwertyu 561 | peter 562 | alexande 563 | steve 564 | bronco 565 | paradise 566 | goober 567 | 5555 568 | samuel 569 | montana 570 | mexico 571 | dreams 572 | michigan 573 | cock 574 | carolina 575 | yankee 576 | friends 577 | magnum 578 | surfer 579 | poopoo 580 | maximus 581 | genius 582 | cool 583 | vampire 584 | lacrosse 585 | asd123 586 | aaaa 587 | christin 588 | kimberly 589 | speedy 590 | sharon 591 | carmen 592 | 111222 593 | kristina 594 | sammy 595 | racing 596 | ou812 597 | sabrina 598 | horses 599 | 0987654321 600 | qwerty1 601 | pimpin 602 | baby 603 | stalker 604 | enigma 605 | 147147 606 | star 607 | poohbear 608 | boobies 609 | 147258 610 | simple 611 | bollocks 612 | 12345q 613 | marcus 614 | brian 615 | 1987 616 | qweasdzxc 617 | drowssap 618 | hahaha 619 | caroline 620 | barbara 621 | dave 622 | viper 623 | drummer 624 | action 625 | einstein 626 | bitches 627 | genesis 628 | hello1 629 | scotty 630 | friend 631 | forest 632 | 010203 633 | hotrod 634 | google 635 | vanessa 636 | spitfire 637 | badger 638 | maryjane 639 | friday 640 | alaska 641 | 1232323q 642 | tester 643 | jester 644 | jake 645 | champion 646 | billy 647 | 147852 648 | rock 649 | hawaii 650 | badass 651 | chevy 652 | 420420 653 | walker 654 | stephen 655 | eagle1 656 | bill 657 | 1986 658 | october 659 | gregory 660 | svetlana 661 | pamela 662 | 1984 663 | music 664 | shorty 665 | westside 666 | stanley 667 | diesel 668 | courtney 669 | 242424 670 | kevin 671 | porno 672 | hitman 673 | boobs 674 | mark 675 | 12345qwert 676 | reddog 677 | frank 678 | qwe123 679 | popcorn 680 | patricia 681 | aaaaaaaa 682 | 1969 683 | teresa 684 | mozart 685 | buddha 686 | anderson 687 | paul 688 | melanie 689 | abcdefg 690 | security 691 | lucky1 692 | lizard 693 | denise 694 | 3333 695 | a12345 696 | 123789 697 | ruslan 698 | stargate 699 | simpsons 700 | scarface 701 | eagle 702 | 123456789a 703 | thumper 704 | olivia 705 | naruto 706 | 1234554321 707 | general 708 | cherokee 709 | a123456 710 | vincent 711 | Usuckballz1 712 | spooky 713 | qweasd 714 | cumshot 715 | free 716 | frankie 717 | douglas 718 | death 719 | 1980 720 | loveyou 721 | kitty 722 | kelly 723 | veronica 724 | suzuki 725 | semperfi 726 | penguin 727 | mercury 728 | liberty 729 | spirit 730 | scotland 731 | natalie 732 | marley 733 | vikings 734 | system 735 | sucker 736 | king 737 | allison 738 | marshall 739 | 1979 740 | 098765 741 | qwerty12 742 | hummer 743 | adrian 744 | 1985 745 | vfhbyf 746 | sandman 747 | rocky 748 | leslie 749 | antonio 750 | 98765432 751 | 4321 752 | softball 753 | passion 754 | mnbvcxz 755 | bastard 756 | passport 757 | horney 758 | rascal 759 | howard 760 | franklin 761 | bigred 762 | assman 763 | alexander 764 | homer 765 | redrum 766 | jupiter 767 | claudia 768 | 55555555 769 | 141414 770 | zaq12wsx 771 | shit 772 | patches 773 | nigger 774 | cunt 775 | raider 776 | infinity 777 | andre 778 | 54321 779 | galore 780 | college 781 | russia 782 | kawasaki 783 | bishop 784 | 77777777 785 | vladimir 786 | money1 787 | freeuser 788 | wildcats 789 | francis 790 | disney 791 | budlight 792 | brittany 793 | 1994 794 | 00000000 795 | sweet 796 | oksana 797 | honda 798 | domino 799 | bulldogs 800 | brutus 801 | swordfis 802 | norman 803 | monday 804 | jimmy 805 | ironman 806 | ford 807 | fantasy 808 | 9999 809 | 7654321 810 | PASSWORD 811 | hentai 812 | duncan 813 | cougar 814 | 1977 815 | jeffrey 816 | house 817 | dancer 818 | brooke 819 | timothy 820 | super 821 | marines 822 | justice 823 | digger 824 | connor 825 | patriots 826 | karina 827 | 202020 828 | molly 829 | everton 830 | tinker 831 | alicia 832 | rasdzv3 833 | poop 834 | pearljam 835 | stinky 836 | naughty 837 | colorado 838 | 123123a 839 | water 840 | test123 841 | ncc1701d 842 | motorola 843 | ireland 844 | asdfg 845 | slut 846 | matt 847 | houston 848 | boogie 849 | zombie 850 | accord 851 | vision 852 | bradley 853 | reggie 854 | kermit 855 | froggy 856 | ducati 857 | avalon 858 | 6666 859 | 9379992 860 | sarah 861 | saints 862 | logitech 863 | chopper 864 | 852456 865 | simpson 866 | madonna 867 | juventus 868 | claire 869 | 159951 870 | zachary 871 | yfnfif 872 | wolverin 873 | warcraft 874 | hello123 875 | extreme 876 | penis 877 | peekaboo 878 | fireman 879 | eugene 880 | brenda 881 | 123654789 882 | russell 883 | panthers 884 | georgia 885 | smith 886 | skyline 887 | jesus 888 | elizabet 889 | spiderma 890 | smooth 891 | pirate 892 | empire 893 | bullet 894 | 8888 895 | virginia 896 | valentin 897 | psycho 898 | predator 899 | arizona 900 | 134679 901 | mitchell 902 | alyssa 903 | vegeta 904 | titanic 905 | christ 906 | goblue 907 | fylhtq 908 | wolf 909 | mmmmmm 910 | kirill 911 | indian 912 | hiphop 913 | baxter 914 | awesome 915 | people 916 | danger 917 | roland 918 | mookie 919 | 741852963 920 | 1111111111 921 | Password01 922 | dreamer 923 | bambam 924 | arnold 925 | 1981 926 | skipper 927 | serega 928 | rolltide 929 | elvis 930 | changeme 931 | simon 932 | 1q2w3e 933 | lovelove 934 | fktrcfylh 935 | denver 936 | tommy 937 | mine 938 | loverboy 939 | hobbes 940 | happy1 941 | alison 942 | nemesis 943 | chevelle 944 | cardinal 945 | burton 946 | wanker 947 | picard 948 | 151515 949 | tweety 950 | michael1 951 | 147852369 952 | 12312 953 | xxxx 954 | windows 955 | turkey 956 | 456789 957 | 1974 958 | vfrcbv 959 | sublime 960 | 1975 961 | galina 962 | bobby 963 | newport 964 | manutd 965 | daddy 966 | american 967 | alexandr 968 | 1966 969 | victory 970 | rooster 971 | qqq111 972 | madmax 973 | electric 974 | bigcock 975 | a1b2c3 976 | wolfpack 977 | spring 978 | phpbb 979 | lalala 980 | suckme 981 | spiderman 982 | eric 983 | darkside 984 | classic 985 | raptor 986 | 123456789q 987 | hendrix 988 | 1982 989 | wombat 990 | avatar 991 | alpha 992 | zxc123 993 | crazy 994 | hard 995 | england 996 | brazil 997 | 1978 998 | 01011980 999 | wildcat 1000 | polina 1001 | freepass 1002 | -------------------------------------------------------------------------------- /start/CH07/Find404.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for 404 errors 3 | # By -------------------------------------------------------------------------------- /start/CH07/FindClients.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for client addresses 3 | # Use RegEx to find and report on most frequent users 4 | # By -------------------------------------------------------------------------------- /start/CH07/FindPotentialHacking.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for possible hacking 3 | # Use RegEx to find and report on common hacking types 4 | # Based on https://www.cgisecurity.com/fingerprinting-port80-attacks-a-look-into-web-server-and-web-application-attack-signatures-part-two.html 5 | # By -------------------------------------------------------------------------------- /start/CH07/FindStatusCodes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans web server logs for status codes 3 | # Use RegEx to find and report on most frequent status messages 4 | # By -------------------------------------------------------------------------------- /start/CH07/README.md: -------------------------------------------------------------------------------- 1 | geolocation api: https://ipstack.com/ 2 | 3 | Im not happy with the geolocate 4 | I think it would be better to further analyze the apache logs for hacking 5 | 6 | possibly include regex examples for CC#, SSN# or other interesting info 7 | 8 | 9 | access.log pulled from http://www.almhuette-raith.at/apache-log/access.log on 3/23/2021 10 | need to sanitize -------------------------------------------------------------------------------- /start/CH08/HaveIBeenPwned.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that checks passwords agains haveibeenpwned.com API 3 | # https://haveibeenpwned.com/API/v3#PwnedPasswords 4 | # By -------------------------------------------------------------------------------- /start/CH08/ListRepositories.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that lists repositories in GitHub 3 | # Requires a Personal Access Token to run 4 | # By -------------------------------------------------------------------------------- /start/CH08/PeopleInSpace1.py: -------------------------------------------------------------------------------- 1 | # paste code here -------------------------------------------------------------------------------- /start/CH08/PeopleInSpace2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that tells us how many people there are in space 3 | #By -------------------------------------------------------------------------------- /start/CH09/CheckURL.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that checks URLs against Google's Safe Browsing API 3 | # https://developers.google.com/safe-browsing/v4 4 | # By -------------------------------------------------------------------------------- /start/CH09/ScanFile.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that scans files using VirusTotal 3 | # https://developers.virustotal.com/reference 4 | # By -------------------------------------------------------------------------------- /start/CH09/test.json: -------------------------------------------------------------------------------- 1 | { 2 | "client": { 3 | "clientId": "yourcompanyname", 4 | "clientVersion": "1.5.2" 5 | }, 6 | "threatInfo": { 7 | "threatTypes": "MALWARE", 8 | "platformTypes": "LINUX", 9 | "threatEntryTypes": "URL", 10 | "threatEntries": {"url": "http://testsafebrowsing.appspot.com/s/malware.html"} 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /start/CH10/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edgoadcom/PythonforCybersecurity/1c042e0a2d03ac25933c52ec26dfd5a786c34e84/start/CH10/README.md -------------------------------------------------------------------------------- /start/CH10/geometry_managers.py: -------------------------------------------------------------------------------- 1 | # Various tkinter geometry managers 2 | # View how pack, grid, place work together 3 | # Created by Ed 11/15 4 | 5 | # Import tkinter 6 | 7 | # Create the GUI main window 8 | 9 | # Using pack in a separate frame 10 | 11 | # Using grid in another frame 12 | 13 | # Using place in the root window 14 | 15 | 16 | # Enter the main event loop 17 | -------------------------------------------------------------------------------- /start/CH10/tkinter_button.py: -------------------------------------------------------------------------------- 1 | # Seconder tkinter script 2 | # Add a button and command 3 | # Create 4 | 5 | # Import tkinter 6 | 7 | # Functions 8 | 9 | # Create the GUI main window 10 | 11 | # Add widgets 12 | 13 | # Enter the main event loop -------------------------------------------------------------------------------- /start/CH10/tkinter_dadjokes.py: -------------------------------------------------------------------------------- 1 | # third tkinter script 2 | # Get people in space 3 | # Create by 4 | 5 | # Import tkinter 6 | 7 | # Functions 8 | 9 | # Create the GUI main window 10 | 11 | # Create font object 12 | # Set wraplength to 25 characters 13 | 14 | # Add widgets 15 | 16 | # Enter the main event loop -------------------------------------------------------------------------------- /start/CH10/tkinter_hello.py: -------------------------------------------------------------------------------- 1 | # First tkinter script 2 | # Create by 3 | 4 | # Import tkinter 5 | 6 | # Create the GUI main window 7 | 8 | # Add widgets 9 | 10 | # Enter the main event loop -------------------------------------------------------------------------------- /start/CH10/tkinter_peopleinspace.py: -------------------------------------------------------------------------------- 1 | # third tkinter script 2 | # Get people in space 3 | # Create by 4 | 5 | # Import tkinter 6 | 7 | # Functions 8 | 9 | # Create the GUI main window 10 | 11 | # Add widgets 12 | 13 | # Enter the main event loop -------------------------------------------------------------------------------- /start/CH11/answer_questions.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that connects to HuggingFace and performs a query 3 | # Requires an API key to run - https://huggingface.co/settings/tokens 4 | # By 5 | 6 | # Import Python modules 7 | 8 | # Define assumptions to go along with the questions 9 | assumptions = [ 10 | "I am a teacher.", 11 | "This is for an elementary school.", 12 | "Responses should be simple and easy to understand." 13 | ] 14 | 15 | # Get API key 16 | 17 | # Ask the user for a prompt 18 | 19 | # Join the assumptions and question, and send to API 20 | 21 | # Print responses 22 | -------------------------------------------------------------------------------- /start/CH11/create_image.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Script that connects to HuggingFace and performs a query 3 | # Requires an API key to run - https://huggingface.co/settings/tokens 4 | # By 5 | 6 | # Import Python modules 7 | 8 | 9 | # Ask the user for a prompt 10 | 11 | # Get API key 12 | 13 | # Generate the image from text 14 | 15 | # Save image to file 16 | --------------------------------------------------------------------------------