Giter Club home page Giter Club logo

blackhat-python3's Introduction

Python 3 "Black Hat Python" Source Code

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 issues of dependency resolution involving deprecated modules.

Although many optimizations could have been implemented in the source code presented throughout the book, the code was left unaltered as much as possible so that such modifications can be applied by the reader as he sees fit. The code as it is needs some serious refactoring efforts ranging from docstrings to type hinting and exception handling, not to mention enhancements like context managers, but these issues by themselves may come to benefit the reader if he has the intention of implementing them. It also presents many bugs originating from indentation that have been corrected if fatal errors were to be avoided during runtime.

Usage

Simply make a new directory (DIR) for the project, create a new virtual environment or "venv" for it (recommended), clone this repository using git clone and install the requirements using pip install.

user@host:~$ mkdir DIR
user@host:~$ cd DIR
user@host:~/DIR$ python3 -m venv venv
user@host:~/DIR$ source venv/bin/activate
(venv) user@host:~/DIR$ git clone https://github.com/EONRaider/blackhat-python3
(venv) user@host:~/DIR$ pip install -r requirements.txt

Notes

  • The book was made available in its entirety by Internet Archive, right here.
  • Some listings presented on the book were missing from the author's code repository available from "no starch press" website and were added to their respective chapters. A more accurate naming convention has been applied to the files as necessary in order to relate them to the code presented in the book.
  • Minor bugs that generated warnings by the interpreter have been fixed throughout the code without altering its characteristics.
  • Auxiliary files that were required to make the code work were added to their respective chapters.
  • As a personal side-note, it could have been possible for the author to have written cleaner code without jeopardizing the quickness of implementation that is required for ethical hacking engagements. Why he opted for not doing so remains of unknown reason.

Refactoring

Critical bug fixes that had to be made in order to properly implement the source code and avoid fatal errors:

  • chapter02/bh_sshserver.py required the RSA key contained in the test_rsa.key file, now included in the corresponding directory.
  • chapter03/sniffer_ip_header_decode.py & sniffer_with_icmp.py & scanner.py all had serious problems in the definition of IP packet sizes and portability between 32/64-bit systems due to problems in the implementation of structs. More about these issues on this thread on Stack Overflow.
  • chapter03/scanner.py used the netaddr module, which is not maintained anymore and presents many incompatibilities with Python 3. For that reason the code has been refactored and now uses the ipaddress module from Stdlib.
  • chapter04/arper.py & mail_sniffer.py used the scapy module, which is not compatible with Python 3. For that reason the code has been refactored and now uses the kamene module.
  • chapter04/pic_carver.py now uses the "opencv-python" library instead of "cv2". The "cv2.cv" module was deprecated and has been replaced. The parameter "cv2.cv.CV_HAAR_SCALE_IMAGE" from the original code was replaced by "cv2.CASCADE_SCALE_IMAGE" because of this commit.
  • chapter05/content_bruter.py required a wordlist to work. It has been added to the chapter under "all.txt".
  • chapter05/joomla_killer.py required a wordlist to work. It has been added to the chapter under "cain.txt".
  • chapter06/bhp_bing.py & bhp_fuzzer.py & bhp_wordlist.py have been reformatted to comply with PEP8, though some warnings will still be triggered due to the necessity to conform class names to camel-casing in this specific application on Burp Suite.
  • chapter06/jython-standalone-2.7.2.jar is available as a more updated version of the file relative to the one presented in the book.
  • chapter07/git_trojan.py was refactored to replace the "imp" module (now deprecated) for "types". A subdirectory structure with the necessary configuration files has been implemented as instructed in the book. The "trojan_config" variable was missing the relative path to the config subdirectory. A call to "to_tree()" method was added to line 60 in order to avoid an AttributeError exception generated by the original code. Instructions on how to generate an access token instead of using one's password in case 2FA is being used were included as comments.
  • chapter08/keylogger.py requires the PyHook module to work. A wheel file has been included with the 1.6.2 version. If necessary, other versions can be downloaded from here.

blackhat-python3's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.