Home

Awesome

<h1 align="center">SimpleHTTPserver</h1> <h4 align="center">Go alternative of python SimpleHTTPServer</h4> <p align="center"> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-_red.svg"></a> <a href="https://github.com/projectdiscovery/simplehttpserver/issues"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat"></a> <a href="https://goreportcard.com/badge/github.com/projectdiscovery/simplehttpserver"><img src="https://goreportcard.com/badge/github.com/projectdiscovery/simplehttpserver"></a> <a href="https://hub.docker.com/r/projectdiscovery/simplehttpserver"><img src="https://img.shields.io/docker/pulls/projectdiscovery/simplehttpserver.svg"></a> <a href="https://twitter.com/pdiscoveryio"><img src="https://img.shields.io/twitter/follow/pdiscoveryio.svg?logo=twitter"></a> <a href="https://discord.gg/projectdiscovery"><img src="https://img.shields.io/discord/695645237418131507.svg?logo=discord"></a> </p> <p align="center"> <a href="#features">Features</a> • <a href="#usage">Usage</a> • <a href="#installing-simplehttpserver">Installation</a> • <a href="#running-simplehttpserver-in-the-current-folder">Run SimpleHTTPserver</a> • <a href="https://discord.gg/projectdiscovery">Join Discord</a> </p>

SimpleHTTPserver is a go enhanced version of the well known python simplehttpserver with in addition a fully customizable TCP server, both supporting TLS.

Features

Installing SimpleHTTPserver

SimpleHTTPserver requires go1.17+ to install successfully. Run the following command to get the repo -

go install -v github.com/projectdiscovery/simplehttpserver/cmd/simplehttpserver@latest

Usage

simplehttpserver -h

This will display help for the tool. Here are all the switches it supports.

FlagDescriptionExample
-listenConfigure listening ip:port (default 127.0.0.1:8000)simplehttpserver -listen 127.0.0.1:8000
-pathFileserver folder (default current directory)simplehttpserver -path /var/docs
-verboseVerbose (dump request/response, default false)simplehttpserver -verbose
-tcpTCP server (default 127.0.0.1:8000)simplehttpserver -tcp 127.0.0.1:8000
-tlsEnable TLS for TCP serversimplehttpserver -tls
-rulesFile containing yaml rulessimplehttpserver -rules rule.yaml
-uploadEnable file upload in case of http serversimplehttpserver -upload
-max-file-sizeMax Upload File Size (default 50 MB)simplehttpserver -max-file-size 100
-sandboxEnable sandbox modesimplehttpserver -sandbox
-httpsEnable HTTPS in case of http serversimplehttpserver -https
-http1Enable only HTTP1simplehttpserver -http1
-certHTTPS/TLS certificate (self generated if not specified)simplehttpserver -cert cert.pem
-keyHTTPS/TLS certificate private keysimplehttpserver -key cert.key
-domainDomain name to use for the self-generated certificatesimplehttpserver -domain projectdiscovery.io
-corsEnable cross-origin resource sharing (CORS)simplehttpserver -cors
-basic-authBasic auth (username:password)simplehttpserver -basic-auth user:password
-realmBasic auth messagesimplehttpserver -realm "insert the credentials"
-versionShow versionsimplehttpserver -version
-silentShow only resultssimplehttpserver -silent
-pyEmulate Python Stylesimplehttpserver -py
-headerHTTP response header (can be used multiple times)simplehttpserver -header 'X-Powered-By: Go'

Running simplehttpserver in the current folder

This will run the tool exposing the current directory on port 8000

simplehttpserver

2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
2021/01/11 21:41:15 [::1]:50181 "GET / HTTP/1.1" 200 383
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19

Running simplehttpserver in the current folder with HTTPS

This will run the tool exposing the current directory on port 8000 over HTTPS with user provided certificate:

simplehttpserver -https -cert cert.pen -key cert.key

2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
2021/01/11 21:41:15 [::1]:50181 "GET / HTTP/1.1" 200 383
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19

Instead, to run with self-signed certificate and specific domain name:

simplehttpserver -https -domain localhost

2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
2021/01/11 21:41:15 [::1]:50181 "GET / HTTP/1.1" 200 383
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19

Running simplehttpserver with basic auth and file upload

This will run the tool and will request the user to enter username and password before authorizing file uploads

simplehttpserver -basic-auth root:root -upload

2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...

To upload files use the following curl request with basic auth header:

curl -v --user 'root:root' --upload-file file.txt http://localhost:8000/file.txt

Running TCP server with custom responses

This will run the tool as TLS TCP server and enable custom responses based on YAML templates:

simplehttpserver -rules rules.yaml -tcp -tls -domain localhost

The rules are written as follows:

rules:
  - match: regex-match
    match-contains: literal-match
    name: rule-name
    response: response data

For example to handle two different paths simulating an HTTP server or SMTP commands:

rules:
  # HTTP Requests
  - match: GET /path1
    name: redirect
    response: |
              HTTP/1.0 200 OK
              Server: httpd/2.0
              x-frame-options: SAMEORIGIN
              x-xss-protection: 1; mode=block
              Date: Fri, 16 Apr 2021 14:30:32 GMT
              Content-Type: text/html
              Connection: close

              <HTML><HEAD><script>top.location.href='/Main_Login.asp';</script>
              </HEAD></HTML>
  - match: GET /path2
    name: "404"
    response: |
              HTTP/1.0 404 OK
              Server: httpd/2.0
            
              <HTML><HEAD></HEAD><BODY>Not found</BODY></HTML>
  # SMTP Commands
  - match: "EHLO example.com"
    name: smtp 
    response: |
              250-localhost Nice to meet you, [127.0.0.1]
              250-PIPELINING
              250-8BITMIME
              250-SMTPUTF8
              250-AUTH LOGIN PLAIN
              250 STARTTLS
  - match: "MAIL FROM: <noreply@example.com>"
    response: 250 Accepted
  - match: "RCPT TO: <test@example.com>"
    response: 250 Accepted

  - match-contains: !!binary |
      MAwCAQFgBwIBAwQAgAA=
    name: "ldap"
    # Request:  300c 0201 0160 0702 0103 0400 8000       0....`........
    # Response: 300c 0201 0161 070a 0100 0400 0400       0....a........
    response: !!binary |
      MAwCAQFhBwoBAAQABAA=

Note

Thanks

SimpleHTTPserver is made with 🖤 by the projectdiscovery team.