Skip to content

Commit b341d68

Browse files
authored
Merge pull request #24 from projectdiscovery/dev
SimpleHTTPserver v0.0.2
2 parents 9db4507 + 80695a6 commit b341d68

File tree

26 files changed

+866
-139
lines changed

26 files changed

+866
-139
lines changed

.github/dependabot.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
9+
# Maintain dependencies for GitHub Actions
10+
- package-ecosystem: "github-actions"
11+
directory: "/"
12+
schedule:
13+
interval: "weekly"
14+
commit-message:
15+
prefix: "chore"
16+
include: "scope"
17+
18+
# Maintain dependencies for go modules
19+
- package-ecosystem: "gomod"
20+
directory: "/"
21+
schedule:
22+
interval: "weekly"
23+
commit-message:
24+
prefix: "chore"
25+
include: "scope"
26+
27+
# Maintain dependencies for docker
28+
- package-ecosystem: "docker"
29+
directory: "/"
30+
schedule:
31+
interval: "weekly"
32+
commit-message:
33+
prefix: "chore"
34+
include: "scope"

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232

3333
- name: Test
3434
run: go test .
35-
working-directory: .
35+
working-directory: cmd/simplehttpserver
3636

3737
- name: Build
3838
run: go build .
39-
working-directory: .
39+
working-directory: cmd/simplehttpserver/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
*.exe
2-
simplehttpserver
2+
cmd/simplehttpserver/simplehttpserver

.golangci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ linters-settings:
4141
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
4242
# lll:
4343
# line-length: 140
44-
maligned:
45-
suggest-new: true
4644
misspell:
4745
locale: US
4846
nolintlint:
@@ -73,14 +71,12 @@ linters:
7371
- gosimple
7472
- govet
7573
- ineffassign
76-
- interfacer
77-
- maligned
7874
- misspell
7975
- nakedret
8076
- noctx
8177
- nolintlint
8278
- rowserrcheck
83-
- scopelint
79+
- exportloopref
8480
- staticcheck
8581
- structcheck
8682
- stylecheck

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
builds:
22
- binary: simplehttpserver
3-
main: simplehttpserver.go
3+
main: cmd/simplehttpserver/simplehttpserver.go
44
goos:
55
- linux
66
- windows

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
FROM golang:1.14-alpine AS builder
1+
FROM golang:1.16-alpine AS builder
22
RUN apk add --no-cache git
3-
RUN GO111MODULE=auto go get -u -v github.com/projectdiscovery/simplehttpserver
3+
RUN GO111MODULE=auto go get -u -v github.com/projectdiscovery/simplehttpserver/cmd/simplehttpserver
44

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

89
ENTRYPOINT ["simplehttpserver"]

README.md

Lines changed: 131 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,44 @@
1-
<h1 align="center">
2-
<img src="static/simplehttpserver-logo.png" alt="simplehttpserver" width="200px"></a>
3-
<br>
4-
</h1>
1+
<h1 align="center">SimpleHTTPserver</h1>
2+
<h4 align="center">Go alternative of python SimpleHTTPServer</h4>
53

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

14-
simplehttpserver is a go enhanced version of the well known python simplehttpserver.
5+
<p align="center">
6+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/license-MIT-_red.svg"></a>
7+
<a href="https://github.com/projectdiscovery/simplehttpserver/issues"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat"></a>
8+
<a href="https://goreportcard.com/badge/github.com/projectdiscovery/simplehttpserver"><img src="https://goreportcard.com/badge/github.com/projectdiscovery/simplehttpserver"></a>
9+
<a href="https://hub.docker.com/r/projectdiscovery/simplehttpserver"><img src="https://img.shields.io/docker/pulls/projectdiscovery/simplehttpserver.svg"></a>
10+
<a href="https://twitter.com/pdiscoveryio"><img src="https://img.shields.io/twitter/follow/pdiscoveryio.svg?logo=twitter"></a>
11+
<a href="https://discord.gg/projectdiscovery"><img src="https://img.shields.io/discord/695645237418131507.svg?logo=discord"></a>
12+
</p>
1513

16-
# Resources
14+
<p align="center">
15+
<a href="#features">Features</a> •
16+
<a href="#usage">Usage</a> •
17+
<a href="#installing-simplehttpserver">Installation</a> •
18+
<a href="#running-simplehttpserver-in-the-current-folder">Run SimpleHTTPserver</a> •
19+
<a href="https://discord.gg/projectdiscovery">Join Discord</a>
20+
</p>
1721

18-
- [Features](#features)
19-
- [Usage](#usage)
20-
- [Installation Instructions](#installation-instructions)
21-
- [Running simplehttpserver](#running-simplehttpserver-in-the-current-folder )
22-
- [Thanks](#thanks)
23-
24-
# Features
25-
26-
<h1 align="left">
27-
<img src="static/simplehttpserver-run.png" alt="simplehttpserver" width="700px"></a>
28-
<br>
29-
</h1>
30-
31-
- File server in arbitrary directory
32-
- Full request/response dump
33-
- Configurable ip address and listening port
34-
35-
36-
# Installation Instructions
22+
---
3723

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

39-
### From Binary
4026

41-
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.
27+
# Features
4228

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

46-
▶ tar -xvf simplehttpserver-linux-amd64.tar
47-
▶ mv simplehttpserver-linux-amd64 /usr/local/bin/simplehttpserver
48-
▶ simplehttpserver -h
49-
```
5035

51-
### From Source
36+
# Installing SimpleHTTPserver
5237

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

5540
```sh
56-
▶ GO111MODULE=on go get -v github.com/projectdiscovery/simplehttpserver
57-
```
58-
59-
### From Github
60-
61-
```sh
62-
▶ git clone https://github.com/projectdiscovery/simplehttpserver.git; cd simplehttpserver; go build; mv simplehttpserver /usr/local/bin/; simplehttpserver -h
41+
▶ GO111MODULE=on go get -v github.com/projectdiscovery/cmd/simplehttpserver
6342
```
6443

6544
# Usage
@@ -70,11 +49,23 @@ simplehttpserver -h
7049

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

73-
| Flag | Description | Example |
74-
| ------ | ---------------------------------------------------- | --------------------------------------- |
75-
| listen | Configure listening ip:port (default 127.0.0.1:8000) | simplehttpserver -listen 127.0.0.1:8000 |
76-
| path | Fileserver folder (default current directory) | simplehttpserver -path /var/docs |
77-
| v | Verbose (dump request/response, default false) | simplehttpserver -v |
52+
| Flag | Description | Example |
53+
| ----------- | -------------------------------------------------------------------- | ------------------------------------------------- |
54+
| listen | Configure listening ip:port (default 127.0.0.1:8000) | simplehttpserver -listen 127.0.0.1:8000 |
55+
| path | Fileserver folder (default current directory) | simplehttpserver -path /var/docs |
56+
| verbose | Verbose (dump request/response, default false) | simplehttpserver -v |
57+
| tcp | TCP server (default 127.0.0.1:8000) | simplehttpserver -tcp 127.0.0.1:8000 |
58+
| tls | Enable TLS for TCP server | simplehttpserver -tls |
59+
| rules | File containing yaml rules | simplehttpserver -rules rule.yaml | |
60+
| upload | Enable file upload in case of http server | simplehttpserver -upload |
61+
| https | Enable HTTPS in case of http server | simplehttpserver -https |
62+
| cert | HTTPS/TLS certificate (self generated if not specified) | simplehttpserver -cert cert.pem |
63+
| key | HTTPS/TLS certificate private key (self generated if not specified) | simplehttpserver -key cert.key |
64+
| domain | Domain name to use for the self-generated certificate | simplehttpserver -domain projectdiscovery.io |
65+
| basic-auth | Basic auth (username:password) | simplehttpserver -basic-auth user:password |
66+
| realm | Basic auth message | simplehttpserver -realm "insert the credentials" |
67+
| version | Show version | simplehttpserver -version |
68+
| silent | Show only results | simplehttpserver -silent |
7869

7970
### Running simplehttpserver in the current folder
8071

@@ -87,6 +78,91 @@ This will run the tool exposing the current directory on port 8000
8778
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19
8879
```
8980

81+
### Running simplehttpserver in the current folder with HTTPS
82+
83+
This will run the tool exposing the current directory on port 8000 over HTTPS with user provided certificate:
84+
85+
```sh
86+
▶ simplehttpserver -https -cert cert.pen -key cert.key
87+
2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
88+
2021/01/11 21:41:15 [::1]:50181 "GET / HTTP/1.1" 200 383
89+
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19
90+
```
91+
92+
Instead, to run with self-signed certificate and specific domain name:
93+
```sh
94+
▶ simplehttpserver -https -domain localhost
95+
2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
96+
2021/01/11 21:41:15 [::1]:50181 "GET / HTTP/1.1" 200 383
97+
2021/01/11 21:41:15 [::1]:50181 "GET /favicon.ico HTTP/1.1" 404 19
98+
```
99+
100+
### Running simplehttpserver with basic auth and file upload
101+
102+
This will run the tool and will request the user to enter username and password before authorizing file uploads
103+
104+
```sh
105+
▶ simplehttpserver -basic-auth root:root -upload
106+
2021/01/11 21:40:48 Serving . on http://0.0.0.0:8000/...
107+
```
108+
109+
To upload files use the following curl request with basic auth header:
110+
```sh
111+
▶ curl -v --user 'root:root' --upload-file file.txt http://localhost:8000/file.txt
112+
```
113+
114+
### Running TCP server with custom responses
115+
116+
This will run the tool as TLS TCP server and enable custom responses based on YAML templates:
117+
118+
```sh
119+
▶ simplehttpserver -rule rules.yaml -tcp -tls -domain localhost
120+
```
121+
122+
The rules are written as follows:
123+
```yaml
124+
rules:
125+
- match: regex
126+
response: response data
127+
```
128+
129+
For example to handle two different paths simulating an HTTP server or SMTP commands:
130+
```yaml
131+
rules:
132+
# HTTP Requests
133+
- match: GET /path1
134+
response: |
135+
HTTP/1.0 200 OK
136+
Server: httpd/2.0
137+
x-frame-options: SAMEORIGIN
138+
x-xss-protection: 1; mode=block
139+
Date: Fri, 16 Apr 2021 14:30:32 GMT
140+
Content-Type: text/html
141+
Connection: close
142+
143+
<HTML><HEAD><script>top.location.href='/Main_Login.asp';</script>
144+
</HEAD></HTML>
145+
- match: GET /path2
146+
response: |
147+
HTTP/1.0 404 OK
148+
Server: httpd/2.0
149+
150+
<HTML><HEAD></HEAD><BODY>Not found</BODY></HTML>
151+
# SMTP Commands
152+
- match: "EHLO example.com"
153+
response: |
154+
250-localhost Nice to meet you, [127.0.0.1]
155+
250-PIPELINING
156+
250-8BITMIME
157+
250-SMTPUTF8
158+
250-AUTH LOGIN PLAIN
159+
250 STARTTLS
160+
- match: "MAIL FROM: <noreply@example.com>"
161+
response: 250 Accepted
162+
- match: "RCPT TO: <test@example.com>"
163+
response: 250 Accepted
164+
```
165+
90166
# Thanks
91167
92-
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.
168+
SimpleHTTPserver is made with 🖤 by the [projectdiscovery](https://projectdiscovery.io) team.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"github.com/projectdiscovery/gologger"
5+
"github.com/projectdiscovery/simplehttpserver/internal/runner"
6+
)
7+
8+
func main() {
9+
// Parse the command line flags and read config files
10+
options := runner.ParseOptions()
11+
r, err := runner.New(options)
12+
if err != nil {
13+
gologger.Fatal().Msgf("Could not create runner: %s\n", err)
14+
}
15+
16+
if err := r.Run(); err != nil {
17+
gologger.Info().Msgf("%s\n", err)
18+
}
19+
defer r.Close() //nolint
20+
}

go.mod

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module github.com/projectdiscovery/simplehttpserver
22

3-
go 1.15
3+
go 1.14
4+
5+
require (
6+
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
7+
github.com/projectdiscovery/gologger v1.1.4
8+
github.com/projectdiscovery/sslcert v0.0.0-20210416140253-8f56bec1bb5e
9+
gopkg.in/yaml.v2 v2.4.0
10+
)

go.sum

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
6+
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
7+
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
8+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
9+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
10+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
11+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
12+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
13+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
14+
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
15+
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
16+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
17+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
18+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
19+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
20+
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
21+
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
22+
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
23+
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
24+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
25+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
26+
github.com/projectdiscovery/gologger v1.1.4 h1:qWxGUq7ukHWT849uGPkagPKF3yBPYAsTtMKunQ8O2VI=
27+
github.com/projectdiscovery/gologger v1.1.4/go.mod h1:Bhb6Bdx2PV1nMaFLoXNBmHIU85iROS9y1tBuv7T5pMY=
28+
github.com/projectdiscovery/sslcert v0.0.0-20210416140253-8f56bec1bb5e h1:IZa08TUGbU7I0HUb9QQt/8wuu2fPZqfnMXwWhtMxei8=
29+
github.com/projectdiscovery/sslcert v0.0.0-20210416140253-8f56bec1bb5e/go.mod h1:jSp8W5zIkNPxAqVdcoFlfv0K5cqogTe65fMinR0Fvuk=
30+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
31+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
32+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
33+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
34+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
35+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
36+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
37+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
38+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
39+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
40+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
41+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)