Skip to content

0.0.5 Release #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
501692e
chore(deps): bump golang from 1.16.6-alpine to 1.16.7-alpine
dependabot[bot] Aug 9, 2021
85bb3ff
Merge pull request #48 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Aug 9, 2021
67007c8
chore(deps): bump golang from 1.16.7-alpine to 1.17.0-alpine
dependabot[bot] Aug 23, 2021
09501ce
Merge pull request #49 from projectdiscovery/dependabot/docker/dev/go…
Mzack9999 Aug 25, 2021
0a0a561
chore(deps): bump golang from 1.17.0-alpine to 1.17.2-alpine
dependabot[bot] Oct 11, 2021
1559e10
Merge pull request #54 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Oct 13, 2021
dae2503
Adding support for http1 mode only
Mzack9999 Oct 16, 2021
99ee932
Fixing memory leak on large file dump via max-dump-body-size
Mzack9999 Oct 16, 2021
5245952
Merge branch 'master' of https://github.com/projectdiscovery/simpleht…
ehsandeep Oct 20, 2021
502ae44
Merge pull request #57 from projectdiscovery/issue-53-memory-leak-on-…
ehsandeep Oct 30, 2021
e0cee73
Merge branch 'dev' into issue-50-h1-only-mode
ehsandeep Oct 30, 2021
9f27f6f
Merge pull request #56 from projectdiscovery/issue-50-h1-only-mode
ehsandeep Oct 30, 2021
8dd2098
chore(deps): bump golang from 1.17.2-alpine to 1.17.3-alpine
dependabot[bot] Nov 8, 2021
ff76503
Merge pull request #58 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Nov 8, 2021
d75fcd0
chore(deps): bump golang from 1.17.3-alpine to 1.17.4-alpine
dependabot[bot] Dec 6, 2021
8d698e9
Merge pull request #59 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Dec 6, 2021
d4fd4c4
chore(deps): bump golang from 1.17.4-alpine to 1.17.5-alpine
dependabot[bot] Dec 13, 2021
d55e2f8
smalle upload refactoring
c-f Oct 13, 2021
d35177c
merged dev
c-f Dec 20, 2021
fa35851
Merge pull request #55 from c-f/upload-dir
ehsandeep Dec 20, 2021
a556dcc
Merge pull request #60 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Dec 20, 2021
4fb2abb
remove bug of reading previous messages
c-f Dec 20, 2021
e615365
add livereloading for rule config
c-f Dec 20, 2021
420a99f
make linter happy
c-f Dec 20, 2021
5f46aab
Adding missing logic to enable TCP TLS server
Mzack9999 Dec 21, 2021
bbfd855
Merge pull request #61 from c-f/livereload
ehsandeep Dec 23, 2021
65f36a2
Merge pull request #62 from projectdiscovery/issue-52-tcp-tls
ehsandeep Dec 23, 2021
342bd07
chore(deps): bump golang from 1.17.5-alpine to 1.17.6-alpine
dependabot[bot] Jan 10, 2022
363d5e9
Merge pull request #63 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Jan 10, 2022
c8430a9
add timestamps
bridge-four Jan 13, 2022
54119c6
Merge pull request #64 from bridge-four/dev
ehsandeep Jan 14, 2022
70f410d
chore(deps): bump golangci/golangci-lint-action from 2 to 3.1.0
dependabot[bot] Feb 28, 2022
7e0e3e2
Merge pull request #66 from projectdiscovery/dependabot/github_action…
ehsandeep Mar 3, 2022
f5624c5
chore(deps): bump actions/checkout from 2 to 3
dependabot[bot] Mar 7, 2022
cb02ccf
chore(deps): bump golang from 1.17.6-alpine to 1.18.0-alpine
dependabot[bot] Mar 21, 2022
8dcf3bd
Merge pull request #69 from projectdiscovery/dependabot/docker/dev/go…
Mzack9999 Apr 4, 2022
1562d35
Merge pull request #68 from projectdiscovery/dependabot/github_action…
Mzack9999 Apr 4, 2022
e87cc40
chore(deps): bump golang from 1.18.0-alpine to 1.18.1-alpine
dependabot[bot] Apr 18, 2022
6003813
Merge branch 'master' of https://github.com/projectdiscovery/simpleht…
ehsandeep Apr 18, 2022
129cf6a
Merge branch 'dev' of https://github.com/projectdiscovery/simplehttps…
ehsandeep Apr 18, 2022
bb71699
Merge branch 'dev' into dependabot/docker/dev/golang-1.18.1-alpine
ehsandeep Apr 18, 2022
cdf8d14
Merge pull request #73 from projectdiscovery/dependabot/docker/dev/go…
ehsandeep Apr 18, 2022
45ffc10
version update
ehsandeep Apr 18, 2022
aeeff51
Merge branch 'dev' of https://github.com/projectdiscovery/simplehttps…
ehsandeep Apr 18, 2022
6f8863d
readme update
ehsandeep Apr 18, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dockerhub-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v3.1.0
with:
version: latest
args: --timeout 5m
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ This will display help for the tool. Here are all the switches it supports.
| `-max-file-size` | Max Upload File Size (default 50 MB) | `simplehttpserver -max-file-size 100` |
| `-sandbox` | Enable sandbox mode | `simplehttpserver -sandbox` |
| `-https` | Enable HTTPS in case of http server | `simplehttpserver -https` |
| `-http1` | Enable only HTTP1 | `simplehttpserver -http1` |
| `-cert` | HTTPS/TLS certificate (self generated if not specified) | `simplehttpserver -cert cert.pem` |
| `-key` | HTTPS/TLS certificate private key | `simplehttpserver -key cert.key` |
| `-domain` | Domain name to use for the self-generated certificate | `simplehttpserver -domain projectdiscovery.io` |
Expand Down Expand Up @@ -128,7 +129,9 @@ simplehttpserver -rule rules.yaml -tcp -tls -domain localhost
The rules are written as follows:
```yaml
rules:
- match: regex
- match: regex-match
match-contains: literal-match
name: rule-name
response: response data
```

Expand All @@ -137,6 +140,7 @@ For example to handle two different paths simulating an HTTP server or SMTP comm
rules:
# HTTP Requests
- match: GET /path1
name: redirect
response: |
HTTP/1.0 200 OK
Server: httpd/2.0
Expand All @@ -149,13 +153,15 @@ rules:
<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
Expand All @@ -167,6 +173,14 @@ rules:
response: 250 Accepted
- match: "RCPT TO: <[email protected]>"
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
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/projectdiscovery/simplehttpserver
go 1.17

require (
github.com/fsnotify/fsnotify v1.5.1
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
Expand All @@ -14,4 +15,5 @@ require (
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -31,6 +33,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
4 changes: 2 additions & 2 deletions internal/runner/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const banner = `
\__ \/ / __ -__ \/ __ \/ / _ \/ /_/ / / / / / / /_/ / ___/ _ \/ ___/ | / / _ \/ ___/
___/ / / / / / / / /_/ / / __/ __ / / / / / / ____(__ ) __/ / | |/ / __/ /
/____/_/_/ /_/ /_/ .___/_/\___/_/ /_/ /_/ /_/ /_/ /____/\___/_/ |___/\___/_/
/_/ - v0.0.4
/_/ - v0.0.5
`

// Version is the current version
const Version = `0.0.4`
const Version = `0.0.5`

// showBanner is used to show the banner to the user
func showBanner() {
Expand Down
5 changes: 4 additions & 1 deletion internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Options struct {
Silent bool
Sandbox bool
MaxFileSize int
HTTP1Only bool
MaxDumpBodySize int
}

// ParseOptions parses the command line options for application
Expand All @@ -56,8 +58,9 @@ func ParseOptions() *Options {
flag.BoolVar(&options.Version, "version", false, "Show version of the software")
flag.BoolVar(&options.Silent, "silent", false, "Show only results in the output")
flag.BoolVar(&options.Sandbox, "sandbox", false, "Enable sandbox mode")
flag.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1")
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size")

flag.IntVar(&options.MaxDumpBodySize, "max-dump-body-size", -1, "Max Dump Body Size")
flag.Parse()

// Read the inputs and configure the logging
Expand Down
13 changes: 13 additions & 0 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/projectdiscovery/simplehttpserver/pkg/binder"
"github.com/projectdiscovery/simplehttpserver/pkg/httpserver"
"github.com/projectdiscovery/simplehttpserver/pkg/tcpserver"
"github.com/projectdiscovery/simplehttpserver/pkg/unit"
)

// Runner is a client for running the enumeration process.
Expand Down Expand Up @@ -41,6 +42,12 @@ func New(options *Options) (*Runner, error) {
if err != nil {
return nil, err
}
watcher, err := watchFile(r.options.RulesFile, serverTCP.LoadTemplate)
if err != nil {
return nil, err
}
defer watcher.Close()

r.serverTCP = serverTCP
return &r, nil
}
Expand All @@ -59,6 +66,8 @@ func New(options *Options) (*Runner, error) {
Verbose: r.options.Verbose,
Sandbox: r.options.Sandbox,
MaxFileSize: r.options.MaxFileSize,
HTTP1Only: r.options.HTTP1Only,
MaxDumpBodySize: unit.ToMb(r.options.MaxDumpBodySize),
})
if err != nil {
return nil, err
Expand All @@ -71,6 +80,10 @@ func New(options *Options) (*Runner, error) {
// Run logic
func (r *Runner) Run() error {
if r.options.EnableTCP {
if r.options.TCPWithTLS {
gologger.Print().Msgf("Serving TCP rule based tls server on tcp://%s", r.options.ListenAddress)
return r.serverTCP.ListenAndServeTLS()
}
gologger.Print().Msgf("Serving TCP rule based server on tcp://%s", r.options.ListenAddress)
return r.serverTCP.ListenAndServe()
}
Expand Down
36 changes: 36 additions & 0 deletions internal/runner/watchdog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package runner

import (
"log"

"github.com/fsnotify/fsnotify"
)

type WatchEvent func(fname string) error

func watchFile(fname string, callback WatchEvent) (watcher *fsnotify.Watcher, err error) {
watcher, err = fsnotify.NewWatcher()
if err != nil {
return
}
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
continue
}
if event.Op&fsnotify.Write == fsnotify.Write {
if err := callback(fname); err != nil {
log.Println("err", err)
}
}
case <-watcher.Errors:
// ignore errors for now
}
}
}()

err = watcher.Add(fname)
return
}
2 changes: 1 addition & 1 deletion pkg/httpserver/authlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

func (t *HTTPServer) basicauthlayer(handler http.Handler) http.HandlerFunc {
func (t *HTTPServer) basicauthlayer(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user, pass, ok := r.BasicAuth()
if !ok || user != t.options.BasicAuthUsername || pass != t.options.BasicAuthPassword {
Expand Down
44 changes: 36 additions & 8 deletions pkg/httpserver/httpserver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package httpserver

import (
"crypto/tls"
"errors"
"net/http"
"os"
Expand All @@ -23,7 +24,9 @@ type Options struct {
BasicAuthReal string
Verbose bool
Sandbox bool
HTTP1Only bool
MaxFileSize int // 50Mb
MaxDumpBodySize int64
}

// HTTPServer instance
Expand All @@ -32,6 +35,9 @@ type HTTPServer struct {
layers http.Handler
}

// LayerHandler is the interface of all layer funcs
type Middleware func(http.Handler) http.Handler

// New http server instance with options
func New(options *Options) (*HTTPServer, error) {
var h HTTPServer
Expand All @@ -50,18 +56,44 @@ func New(options *Options) (*HTTPServer, error) {
if options.Sandbox {
dir = SandboxFileSystem{fs: http.Dir(options.Folder), RootFolder: options.Folder}
}
h.layers = h.loglayer(http.FileServer(dir))

httpHandler := http.FileServer(dir)
addHandler := func(newHandler Middleware) {
httpHandler = newHandler(httpHandler)
}

// middleware
if options.EnableUpload {
addHandler(h.uploadlayer)
}

if options.BasicAuthUsername != "" || options.BasicAuthPassword != "" {
h.layers = h.loglayer(h.basicauthlayer(http.FileServer(dir)))
addHandler(h.basicauthlayer)
}

httpHandler = h.loglayer(httpHandler)

// add handler
h.layers = httpHandler
h.options = options

return &h, nil
}

func (t *HTTPServer) makeHTTPServer(tlsConfig *tls.Config) *http.Server {
httpServer := &http.Server{Addr: t.options.ListenAddress}
if t.options.HTTP1Only {
httpServer.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler))
}
httpServer.TLSConfig = tlsConfig
httpServer.Handler = t.layers
return httpServer
}

// ListenAndServe requests over http
func (t *HTTPServer) ListenAndServe() error {
return http.ListenAndServe(t.options.ListenAddress, t.layers)
httpServer := t.makeHTTPServer(nil)
return httpServer.ListenAndServe()
}

// ListenAndServeTLS requests over https
Expand All @@ -73,11 +105,7 @@ func (t *HTTPServer) ListenAndServeTLS() error {
if err != nil {
return err
}
httpServer := &http.Server{
Addr: t.options.ListenAddress,
TLSConfig: tlsConfig,
}
httpServer.Handler = t.layers
httpServer := t.makeHTTPServer(tlsConfig)
return httpServer.ListenAndServeTLS("", "")
}
return http.ListenAndServeTLS(t.options.ListenAddress, t.options.Certificate, t.options.CertificateKey, t.layers)
Expand Down
Loading