Source code for the book Black Hat Python by Justin Seitz. The code has been fully converted to Python 3, reformatted to comply with PEP8 standards, and refactored to eliminate dependency issues involving deprecated libraries.
Although many optimizations could have been implemented in the source code presented throughout the book, the code was left unaltered as much as possible to allow readers to apply such modifications as they see fit. The code, as it is, requires serious refactoring efforts ranging from docstrings to type hinting and exception handling, not to mention enhancements like context managers. However, these issues may benefit readers by encouraging them to implement these improvements. Many bugs, primarily related to indentation, have been corrected to prevent fatal errors during runtime.
A similar conversion has been made available by me for the source code of the book Violent Python by TJ O'Connor. Check it out here if you haven't done so yet.
Simply choose a directory (DIR) to clone the project using git clone, create a new virtual environment (venv) for it (recommended), and install the requirements using pip install:
user@host:~/DIR$ git clone https://github.com/EONRaider/blackhat-python3
user@host:~/DIR$ python3 -m venv venv
user@host:~/DIR$ source venv/bin/activate
(venv) user@host:~/DIR$ pip install -r requirements.txt- Some listings presented in the book were missing from the author's code repository (available on the No Starch Press website) and have been added to their respective chapters. A more accurate naming convention has been applied to the files to relate them to the book's code.
- Minor bugs that generated warnings from the interpreter have been fixed without altering the code's core characteristics.
- Auxiliary files required to make the code work have been added to their respective chapters.
- On a personal note, the author could have written cleaner code without jeopardizing the quickness required for ethical hacking engagements. Why this wasn't done remains unclear.
Critical bug fixes made to ensure proper implementation and to avoid fatal errors:
chapter02/bh_sshserver.py: Required the RSA key from thetest_rsa.keyfile, now included in the corresponding directory.chapter03/sniffer_ip_header_decode.py,sniffer_with_icmp.py, andscanner.py: Had significant issues in IP packet size definitions and 32/64-bit portability due to problems instruct. More details can be found in this Stack Overflow thread.chapter03/scanner.py: Used thenetaddrlibrary, which is no longer maintained and incompatible with Python 3. It has been refactored to use theipaddressmodule from Python's standard library.chapter04/arper.pyandmail_sniffer.py: Used thescapylibrary, which is incompatible with Python 3. The code now uses thekamenelibrary.chapter04/pic_carver.py: Replaced the deprecatedcv2.cvmodule with theopencv-pythonlibrary. Parameters were updated according to this commit.chapter05/content_bruter.pyandjoomla_killer.py: Added required wordlists (all.txtandcain.txt) to their respective chapters.chapter06/bhp_bing.py,bhp_fuzzer.py, andbhp_wordlist.py: Reformatted to comply with PEP8 standards, though some warnings persist due to specific class naming conventions required by Burp Suite.chapter07/git_trojan.py: Refactored to replace the deprecatedimplibrary withtypes. A subdirectory structure and configuration files were added, and a missing relative path in the "trojan_config" variable was corrected. A call to theto_treemethod was added to avoidAttributeError.chapter08/keylogger.py: Requires thePyHooklibrary. A wheel file for version 1.6.2 has been included. Other versions can be downloaded here.chapter09/ie_exfil.py: Fixed errors in handling theplaintextvariable (string vs binary string) in theencrypt_stringfunction. Corrected the use of thebase64library. Thanks to Enraged for their contribution in this commit.
Contributions in other languages:
To contribute, discuss your proposed changes via an issue before making modifications.
- Ensure your modifications justify a pull request. Minor changes (1–2 lines) should be requested through an issue.
- Update the
README.mdfile if necessary to reflect project structure changes. - Follow a commit message standard. Refer to this guide if unsure.
- Your request will be reviewed within 48 hours.