Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
52aa568
adding http basic auth
Mzack9999 Feb 15, 2021
8ad8b6e
adding file upload support
Mzack9999 Feb 15, 2021
6b4eb1c
adding https support
Mzack9999 Feb 15, 2021
8890cbf
cert generation helper
Mzack9999 Feb 15, 2021
0fc0dea
Update build.yaml
ehsandeep Feb 15, 2021
ae48cc6
Update build.yaml
ehsandeep Feb 15, 2021
8c1cc03
Update build.yaml
ehsandeep Feb 15, 2021
b71f31e
Update build.yaml
ehsandeep Feb 15, 2021
ed7e2ee
linting fix
Mzack9999 Feb 15, 2021
655ee57
Merge pull request #7 from projectdiscovery/feature-https-support
Mzack9999 Feb 17, 2021
f8d7740
Merge branch 'dev' into feature-file-upload
Mzack9999 Feb 17, 2021
04ff1b9
Merge pull request #6 from projectdiscovery/feature-file-upload
Mzack9999 Feb 17, 2021
5fee727
Merge branch 'dev' into feature-basic-auth
Mzack9999 Feb 17, 2021
6f70fed
Merge pull request #5 from projectdiscovery/feature-basic-auth
Mzack9999 Feb 17, 2021
752b822
adding dep bot
Mzack9999 Feb 17, 2021
71c06d3
Merge pull request #8 from projectdiscovery/feature-dep-bot
Mzack9999 Feb 17, 2021
526bfd9
refactoring basic auth option
Mzack9999 Feb 19, 2021
1593493
fixing split amount
Mzack9999 Feb 23, 2021
5a1f3a3
replacing log with gologger
Mzack9999 Feb 23, 2021
7538375
adding auto port increment
Mzack9999 Feb 23, 2021
69d59ff
fixing lint errors
Mzack9999 Feb 23, 2021
e1b3244
Merge pull request #13 from projectdiscovery/maintenance-log-to-gologger
Mzack9999 Feb 23, 2021
260a0d7
Merge branch 'dev' into feature-basic-auth-single-option
Mzack9999 Feb 23, 2021
bfe2804
adding self certificate generation
Mzack9999 Feb 23, 2021
9a1d1df
Merge pull request #11 from projectdiscovery/feature-basic-auth-singl…
ehsandeep Feb 23, 2021
8cc0592
Merge branch 'dev' into feature-port-auto-retry
ehsandeep Feb 23, 2021
86e2a7d
improved output
Mzack9999 Feb 23, 2021
bd654bf
adding missing buffer flush
Mzack9999 Feb 23, 2021
bbee79f
adding initial implementation of template based tcp server
Mzack9999 Feb 23, 2021
c8614c5
fixing conflict
Mzack9999 Feb 23, 2021
ca04767
adding missing buffer flush
Mzack9999 Feb 23, 2021
7bfbf59
fixing name
Mzack9999 Feb 23, 2021
d728e2f
replacing log => gologger
Mzack9999 Feb 23, 2021
8425b05
Merge pull request #14 from projectdiscovery/feature-port-auto-retry
Mzack9999 Feb 24, 2021
f01e6be
Merge branch 'dev' into feature-tcp-server
Mzack9999 Feb 24, 2021
ca92108
removing log package
Mzack9999 Feb 24, 2021
52b211d
Merge pull request #19 from projectdiscovery/bugfix-removing-unused-lib
Mzack9999 Feb 24, 2021
9be5b1a
removing unused log
Mzack9999 Feb 24, 2021
0dfe704
Merge pull request #18 from projectdiscovery/feature-tcp-server
Mzack9999 Feb 24, 2021
c8f58a6
Merge branch 'dev' into feature-generating-self-signed-certificates
Mzack9999 Feb 24, 2021
2e0edf0
Merge pull request #16 from projectdiscovery/feature-generating-self-…
Mzack9999 Feb 24, 2021
c339cd7
code refactor
Mzack9999 Feb 26, 2021
3ae260a
Merge pull request #20 from projectdiscovery/maintenance-code-refactor
Mzack9999 Feb 26, 2021
ced7194
bind logic refactor
Mzack9999 Feb 26, 2021
254d461
misc
Mzack9999 Feb 26, 2021
7a0364f
Merge pull request #21 from projectdiscovery/maintenance-freeport-bind
Mzack9999 Feb 26, 2021
80f5074
adding missing files
Mzack9999 Feb 26, 2021
ae67bbb
Merge pull request #22 from projectdiscovery/bugfix-missing-files
Mzack9999 Feb 26, 2021
fb9d1df
adding common tools to docker
Mzack9999 Apr 16, 2021
49ceaa7
removing sslcert + deps bump
Mzack9999 Apr 16, 2021
d068ebe
using go 1.14
Mzack9999 Apr 16, 2021
e55d3fe
updated readme
Mzack9999 Apr 16, 2021
ef3b178
Update build.yaml
ehsandeep Apr 16, 2021
bce92ad
reverting working-directory
ehsandeep Apr 16, 2021
566a82a
adding absolute path
Mzack9999 Apr 16, 2021
1fe30e1
adding comments
Mzack9999 Apr 16, 2021
b0911c1
adding missing error checks
Mzack9999 Apr 16, 2021
309e6bc
adding missing go docs
Mzack9999 Apr 16, 2021
89bbfaa
fixing misc lint errors
Mzack9999 Apr 16, 2021
8a339ee
bumping version
Mzack9999 Apr 16, 2021
98e4a83
Merge pull request #23 from projectdiscovery/docs-readme
ehsandeep Apr 16, 2021
1b9328d
Update README.md
ehsandeep Apr 16, 2021
d490ff6
Update README.md
ehsandeep Apr 16, 2021
63f26b4
Update .gitignore
ehsandeep Apr 16, 2021
80695a6
banner update
ehsandeep Apr 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
include: "scope"

# Maintain dependencies for go modules
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
include: "scope"

# Maintain dependencies for docker
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "chore"
include: "scope"
17 changes: 4 additions & 13 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,18 @@ on:
pull_request:

jobs:
lint:
name: golangci-lint
golangci-lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v2.2.0
uses: golangci/golangci-lint-action@v2.4.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.31
args: --timeout 5m

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
build:
name: Build
runs-on: ubuntu-latest
Expand All @@ -41,8 +32,8 @@ jobs:

- name: Test
run: go test .
working-directory: .
working-directory: cmd/simplehttpserver

- name: Build
run: go build .
working-directory: .
working-directory: cmd/simplehttpserver/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.exe
simplehttpserver
cmd/simplehttpserver/simplehttpserver
6 changes: 1 addition & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ linters-settings:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
# lll:
# line-length: 140
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
Expand Down Expand Up @@ -73,14 +71,12 @@ linters:
- gosimple
- govet
- ineffassign
- interfacer
- maligned
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- scopelint
- exportloopref
- staticcheck
- structcheck
- stylecheck
Expand Down
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
builds:
- binary: simplehttpserver
main: simplehttpserver.go
main: cmd/simplehttpserver/simplehttpserver.go
goos:
- linux
- windows
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM golang:1.14-alpine AS builder
FROM golang:1.16-alpine AS builder
RUN apk add --no-cache git
RUN GO111MODULE=auto go get -u -v github.com/projectdiscovery/simplehttpserver
RUN GO111MODULE=auto go get -u -v github.com/projectdiscovery/simplehttpserver/cmd/simplehttpserver

FROM alpine:latest
RUN apk add --no-cache bind-tools ca-certificates
COPY --from=builder /go/bin/simplehttpserver /usr/local/bin/

ENTRYPOINT ["simplehttpserver"]
186 changes: 131 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,44 @@
<h1 align="center">
<img src="static/simplehttpserver-logo.png" alt="simplehttpserver" width="200px"></a>
<br>
</h1>
<h1 align="center">SimpleHTTPserver</h1>
<h4 align="center">Go alternative of python SimpleHTTPServer</h4>

[![License](https://img.shields.io/badge/license-MIT-_red.svg)](https://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/projectdiscovery/simplehttpserver)](https://goreportcard.com/report/github.com/projectdiscovery/simplehttpserver)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/projectdiscovery/simplehttpserver/issues)
[![GitHub Release](https://img.shields.io/github/release/projectdiscovery/simplehttpserver)](https://github.com/projectdiscovery/simplehttpserver/releases)
[![Follow on Twitter](https://img.shields.io/twitter/follow/pdiscoveryio.svg?logo=twitter)](https://twitter.com/pdiscoveryio)
[![Docker Images](https://img.shields.io/docker/pulls/projectdiscovery/simplehttpserver.svg)](https://hub.docker.com/r/projectdiscovery/simplehttpserver)
[![Chat on Discord](https://img.shields.io/discord/695645237418131507.svg?logo=discord)](https://discord.gg/KECAGdH)

simplehttpserver is a go enhanced version of the well known python simplehttpserver.
<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>

# Resources
<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>

- [Features](#features)
- [Usage](#usage)
- [Installation Instructions](#installation-instructions)
- [Running simplehttpserver](#running-simplehttpserver-in-the-current-folder )
- [Thanks](#thanks)

# Features

<h1 align="left">
<img src="static/simplehttpserver-run.png" alt="simplehttpserver" width="700px"></a>
<br>
</h1>

- File server in arbitrary directory
- Full request/response dump
- Configurable ip address and listening port


# Installation Instructions
---

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

### From Binary

The installation is easy. You can download the pre-built binaries for your platform from the [Releases](https://github.com/projectdiscovery/simplehttpserver/releases/) page. Extract them using tar, move it to your `$PATH`and you're ready to go.
# Features

```sh
Download latest binary from https://github.com/projectdiscovery/simplehttpserver/releases
- HTTPS support
- File server in arbitrary directory
- Full request/response dump
- Configurable ip address and listening port
- Configurable HTTP/TCP server with customizable response via YAML template

▶ tar -xvf simplehttpserver-linux-amd64.tar
▶ mv simplehttpserver-linux-amd64 /usr/local/bin/simplehttpserver
▶ simplehttpserver -h
```

### From Source
# Installing SimpleHTTPserver

simplehttpserver requires **go1.14+** to install successfully. Run the following command to get the repo -
SimpleHTTPserver requires **go1.14+** to install successfully. Run the following command to get the repo -

```sh
▶ GO111MODULE=on go get -v github.com/projectdiscovery/simplehttpserver
```

### From Github

```sh
▶ git clone https://github.com/projectdiscovery/simplehttpserver.git; cd simplehttpserver; go build; mv simplehttpserver /usr/local/bin/; simplehttpserver -h
▶ GO111MODULE=on go get -v github.com/projectdiscovery/cmd/simplehttpserver
```

# Usage
Expand All @@ -70,11 +49,23 @@ simplehttpserver -h

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

| Flag | Description | Example |
| ------ | ---------------------------------------------------- | --------------------------------------- |
| listen | Configure listening ip:port (default 127.0.0.1:8000) | simplehttpserver -listen 127.0.0.1:8000 |
| path | Fileserver folder (default current directory) | simplehttpserver -path /var/docs |
| v | Verbose (dump request/response, default false) | simplehttpserver -v |
| Flag | Description | Example |
| ----------- | -------------------------------------------------------------------- | ------------------------------------------------- |
| listen | Configure listening ip:port (default 127.0.0.1:8000) | simplehttpserver -listen 127.0.0.1:8000 |
| path | Fileserver folder (default current directory) | simplehttpserver -path /var/docs |
| verbose | Verbose (dump request/response, default false) | simplehttpserver -v |
| tcp | TCP server (default 127.0.0.1:8000) | simplehttpserver -tcp 127.0.0.1:8000 |
| tls | Enable TLS for TCP server | simplehttpserver -tls |
| rules | File containing yaml rules | simplehttpserver -rules rule.yaml | |
| upload | Enable file upload in case of http server | simplehttpserver -upload |
| https | Enable HTTPS in case of http server | simplehttpserver -https |
| cert | HTTPS/TLS certificate (self generated if not specified) | simplehttpserver -cert cert.pem |
| key | HTTPS/TLS certificate private key (self generated if not specified) | simplehttpserver -key cert.key |
| domain | Domain name to use for the self-generated certificate | simplehttpserver -domain projectdiscovery.io |
| basic-auth | Basic auth (username:password) | simplehttpserver -basic-auth user:password |
| realm | Basic auth message | simplehttpserver -realm "insert the credentials" |
| version | Show version | simplehttpserver -version |
| silent | Show only results | simplehttpserver -silent |

### Running simplehttpserver in the current folder

Expand All @@ -87,6 +78,91 @@ This will run the tool exposing the current directory on port 8000
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:

```sh
▶ 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:
```sh
▶ 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

```sh
▶ 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:
```sh
▶ 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:

```sh
▶ simplehttpserver -rule rules.yaml -tcp -tls -domain localhost
```

The rules are written as follows:
```yaml
rules:
- match: regex
response: response data
```

For example to handle two different paths simulating an HTTP server or SMTP commands:
```yaml
rules:
# HTTP Requests
- match: GET /path1
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
response: |
HTTP/1.0 404 OK
Server: httpd/2.0

<HTML><HEAD></HEAD><BODY>Not found</BODY></HTML>
# SMTP Commands
- match: "EHLO example.com"
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
```

# Thanks

simplehttpserver is made with 🖤 by the [projectdiscovery](https://projectdiscovery.io) team. Community contributions have made the project what it is. See the **[Thanks.md](https://github.com/projectdiscovery/simplehttpserver/blob/master/THANKS.md)** file for more details.
SimpleHTTPserver is made with 🖤 by the [projectdiscovery](https://projectdiscovery.io) team.
20 changes: 20 additions & 0 deletions cmd/simplehttpserver/simplehttpserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/simplehttpserver/internal/runner"
)

func main() {
// Parse the command line flags and read config files
options := runner.ParseOptions()
r, err := runner.New(options)
if err != nil {
gologger.Fatal().Msgf("Could not create runner: %s\n", err)
}

if err := r.Run(); err != nil {
gologger.Info().Msgf("%s\n", err)
}
defer r.Close() //nolint
}
9 changes: 8 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module github.com/projectdiscovery/simplehttpserver

go 1.15
go 1.14

require (
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/projectdiscovery/gologger v1.1.4
github.com/projectdiscovery/sslcert v0.0.0-20210416140253-8f56bec1bb5e
gopkg.in/yaml.v2 v2.4.0
)
Loading