Skip to content

Commit e0cee73

Browse files
authored
Merge branch 'dev' into issue-50-h1-only-mode
2 parents dae2503 + 502ae44 commit e0cee73

File tree

11 files changed

+105
-49
lines changed

11 files changed

+105
-49
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
blank_issues_enabled: false
2+
3+
contact_links:
4+
- name: Ask an question / advise on using simplehttpserver
5+
url: https://github.com/projectdiscovery/simplehttpserver/discussions/categories/q-a
6+
about: Ask a question or request support for using simplehttpserver
7+
8+
- name: Share idea / feature to discuss for simplehttpserver
9+
url: https://github.com/projectdiscovery/simplehttpserver/discussions/categories/ideas
10+
about: Share idea / feature to discuss for simplehttpserver
11+
12+
- name: Connect with PD Team (Discord)
13+
url: https://discord.gg/projectdiscovery
14+
about: Connect with PD Team for direct communication
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
name: Feature request
3+
about: Request feature to implement in this project
4+
labels: 'Type: Enhancement'
5+
---
6+
7+
<!--
8+
1. Please make sure to provide a detailed description with all the relevant information that might be required to start working on this feature.
9+
2. In case you are not sure about your request or whether the particular feature is already supported or not, please start a discussion instead.
10+
3. GitHub Discussion: https://github.com/projectdiscovery/simplehttpserver/discussions/categories/ideas
11+
4. Join our discord server at https://discord.gg/projectdiscovery to discuss the idea on the #simplehttpserver channel.
12+
-->
13+
14+
### Please describe your feature request:
15+
<!-- A clear and concise description of feature to implement -->
16+
17+
### Describe the use case of this feature:
18+
<!-- A clear and concise description of the feature request's motivation and the use-cases in which it could be useful. -->
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Issue report
3+
about: Create a report to help us to improve the project
4+
labels: 'Type: Bug'
5+
6+
---
7+
8+
<!--
9+
1. Please search to see if an issue already exists for the bug you encountered.
10+
2. For support requests, FAQs or "How to" questions, please use the GitHub Discussions section instead - https://github.com/projectdiscovery/simplehttpserver/discussions or
11+
3. Join our discord server at https://discord.gg/projectdiscovery and post the question on the #simplehttpserver channel.
12+
-->
13+
14+
<!-- ISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION. -->
15+
16+
### simplehttpserver version:
17+
<!-- You can find current version of simplehttpserver with "simplehttpserver -version" -->
18+
<!-- We only accept issues that are reproducible on the latest version of simplehttpserver. -->
19+
<!-- You can find the latest version of project at https://github.com/projectdiscovery/simplehttpserver/releases/ -->
20+
21+
### Current Behavior:
22+
<!-- A concise description of what you're experiencing. -->
23+
24+
### Expected Behavior:
25+
<!-- A concise description of what you expected to happen. -->
26+
27+
### Steps To Reproduce:
28+
<!--
29+
Example: steps to reproduce the behavior:
30+
1. Run 'simplehttpserver ..'
31+
2. See error...
32+
-->
33+
34+
35+
### Anything else:
36+
<!-- Links? References? Screnshots? Anything that will give us more context about the issue that you are encountering! -->

.github/feature_request.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/issue-report.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

internal/runner/options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Options struct {
3232
Sandbox bool
3333
MaxFileSize int
3434
HTTP1Only bool
35+
MaxDumpBodySize int
3536
}
3637

3738
// ParseOptions parses the command line options for application
@@ -57,9 +58,9 @@ func ParseOptions() *Options {
5758
flag.BoolVar(&options.Version, "version", false, "Show version of the software")
5859
flag.BoolVar(&options.Silent, "silent", false, "Show only results in the output")
5960
flag.BoolVar(&options.Sandbox, "sandbox", false, "Enable sandbox mode")
60-
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size in Mb")
6161
flag.BoolVar(&options.HTTP1Only, "http1", false, "Enable only HTTP1")
62-
62+
flag.IntVar(&options.MaxFileSize, "max-file-size", 50, "Max Upload File Size")
63+
flag.IntVar(&options.MaxDumpBodySize, "max-dump-body-size", -1, "Max Dump Body Size")
6364
flag.Parse()
6465

6566
// Read the inputs and configure the logging

internal/runner/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/projectdiscovery/simplehttpserver/pkg/binder"
66
"github.com/projectdiscovery/simplehttpserver/pkg/httpserver"
77
"github.com/projectdiscovery/simplehttpserver/pkg/tcpserver"
8+
"github.com/projectdiscovery/simplehttpserver/pkg/unit"
89
)
910

1011
// Runner is a client for running the enumeration process.
@@ -60,6 +61,7 @@ func New(options *Options) (*Runner, error) {
6061
Sandbox: r.options.Sandbox,
6162
MaxFileSize: r.options.MaxFileSize,
6263
HTTP1Only: r.options.HTTP1Only,
64+
MaxDumpBodySize: unit.ToMb(r.options.MaxDumpBodySize),
6365
})
6466
if err != nil {
6567
return nil, err

pkg/httpserver/httpserver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ type Options struct {
2424
BasicAuthReal string
2525
Verbose bool
2626
Sandbox bool
27-
MaxFileSize int
2827
HTTP1Only bool
28+
MaxFileSize int // 50Mb
29+
MaxDumpBodySize int64
2930
}
3031

3132
// HTTPServer instance

pkg/httpserver/loglayer.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"path/filepath"
1010

1111
"github.com/projectdiscovery/gologger"
12+
"github.com/projectdiscovery/simplehttpserver/pkg/unit"
1213
)
1314

1415
// Convenience globals
@@ -17,10 +18,19 @@ var (
1718
EnableVerbose bool
1819
)
1920

21+
func (t *HTTPServer) shouldDumpBody(bodysize int64) bool {
22+
return t.options.MaxDumpBodySize > 0 && bodysize > t.options.MaxDumpBodySize
23+
}
24+
2025
func (t *HTTPServer) loglayer(handler http.Handler) http.Handler {
2126
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
22-
fullRequest, _ := httputil.DumpRequest(r, true)
23-
lrw := newLoggingResponseWriter(w)
27+
var fullRequest []byte
28+
if t.shouldDumpBody(r.ContentLength) {
29+
fullRequest, _ = httputil.DumpRequest(r, false)
30+
} else {
31+
fullRequest, _ = httputil.DumpRequest(r, true)
32+
}
33+
lrw := newLoggingResponseWriter(w, t.options.MaxDumpBodySize)
2434
handler.ServeHTTP(lrw, r)
2535

2636
// Handles file write if enabled
@@ -52,7 +62,7 @@ func (t *HTTPServer) loglayer(handler http.Handler) http.Handler {
5262
err error
5363
)
5464
if t.options.Sandbox {
55-
maxFileSize := toMb(t.options.MaxFileSize)
65+
maxFileSize := unit.ToMb(t.options.MaxFileSize)
5666
// check header content length
5767
if r.ContentLength > maxFileSize {
5868
gologger.Print().Msg("request too large")
@@ -81,24 +91,29 @@ func (t *HTTPServer) loglayer(handler http.Handler) http.Handler {
8191
lrw.Header().Write(headers) //nolint
8292
gologger.Print().Msgf("\nRemote Address: %s\n%s\n%s %d %s\n%s\n%s\n", r.RemoteAddr, string(fullRequest), r.Proto, lrw.statusCode, http.StatusText(lrw.statusCode), headers.String(), string(lrw.Data))
8393
} else {
84-
gologger.Print().Msgf("%s \"%s %s %s\" %d %d", r.RemoteAddr, r.Method, r.URL, r.Proto, lrw.statusCode, len(lrw.Data))
94+
gologger.Print().Msgf("%s \"%s %s %s\" %d %d", r.RemoteAddr, r.Method, r.URL, r.Proto, lrw.statusCode, lrw.Size)
8595
}
8696
})
8797
}
8898

8999
type loggingResponseWriter struct {
90100
http.ResponseWriter
91-
statusCode int
92-
Data []byte
101+
statusCode int
102+
Data []byte
103+
Size int
104+
MaxDumpSize int64
93105
}
94106

95-
func newLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter {
96-
return &loggingResponseWriter{w, http.StatusOK, []byte{}}
107+
func newLoggingResponseWriter(w http.ResponseWriter, maxSize int64) *loggingResponseWriter {
108+
return &loggingResponseWriter{w, http.StatusOK, []byte{}, 0, maxSize}
97109
}
98110

99111
// Write the data
100112
func (lrw *loggingResponseWriter) Write(data []byte) (int, error) {
101-
lrw.Data = append(lrw.Data, data...)
113+
if len(lrw.Data) < int(lrw.MaxDumpSize) {
114+
lrw.Data = append(lrw.Data, data...)
115+
}
116+
lrw.Size += len(data)
102117
return lrw.ResponseWriter.Write(data)
103118
}
104119

pkg/httpserver/util.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)