Giter Site home page Giter Site logo

httpserver-plus's Introduction

HTTPServer Plus

-> An improved version of Python's http.server, created for redirection purposes.

I’m sharing this script because I found it incredibly useful, and I hope many of you will too. Feel free to share any improvements or suggestions. Happy Hacking!

Description

When I was perfoming a penetration test, I needed to host HTML files because the default Python server was downloading the files instead of rendering them. Additionally, the URLs couldn't contain dots. To solve this, I created a simple script to redirect users to specific HTML pages.

As shown in the image below, you can define routes. For example, if the user navigates to localhost/about, they will be redirected to localhost/about.html. This allows you to use clean URLs while still pointing to the desired HTML files.

Defined-routes-example

In the image below, you'll notice that the user received a 200 status code despite visiting /about instead of /about.html. This is because the user got redirected.

Defined-routes-example2

You can run the server with HTTPS, by using a self-signed certificate:

78e0f69ba4ab9414512e6c6909c92865.png

Note: In the images above, I'm running a bash file named httpserver that runs httpserver_plus.py. This is the bash file contents:

python3 /path/to/python/script/httpserver_plus.py $@

Usage

usage: httpserver-plus.py [-h] [-p PORT] [-d DIRECTORY] [-sc [SSL_CERTIFICATE]] [-sk [SSL_KEY]]

An improved version of Pythons http.server, created for redirection purposes.

Rerout Example: localhost/about -> localhost/about.html

options:
  -h, --help            show this help message and exit
  -p PORT, --port PORT  Specify Port to use.
  -d DIRECTORY, --directory DIRECTORY
                        Specify directory where .html pages are stored.
  -sc [SSL_CERTIFICATE], --ssl-certificate [SSL_CERTIFICATE]
                        Specify the path to SSL's .cert file, to use HTTPS.
  -sk [SSL_KEY], --ssl-key [SSL_KEY]
                        Specify the path to SSL's .key file, to use HTTPS.

[HTTP Usage Example]
 sudo python3 httpserver_plus.py -p <PORT> -d <path-to-directory-with-html-files>

[HTTPS Usage Example]
 1. Generate a self-signed SSL Certificate.
  openssl req -new -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out public.crt -keyout private.key
 2. Run the script with -sc and -sk flags.
  sudo python3 httpserver_plus.py -p <PORT> -d "<path-to-directory-with-html-files>" -sc "<path-to-server.crt-file>" -sk "<path-to-server.key-file>"

httpserver-plus's People

Contributors

wafflesexploits avatar

Stargazers

Jordan Ovrè avatar

Watchers

 avatar

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.