Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ CONFIG:
-dr, -dynamic-resp enable setting up arbitrary response data
-cr, -custom-records string custom dns records YAML file for DNS server
-hi, -http-index string custom index file for http server
-dhr, -default-http-response string file to serve for all http requests (takes priority over other options)
-hd, -http-directory string directory with files to serve with http server
-ds, -disk disk based storage
-dsp, -disk-path string disk storage path
Expand Down
1 change: 1 addition & 0 deletions cmd/interactsh-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
flagSet.StringVarP(&cliOptions.CustomRecords, "custom-records", "cr", "", "custom dns records YAML file for DNS server"),
flagSet.StringVarP(&cliOptions.HTTPIndex, "http-index", "hi", "", "custom index file for http server"),
flagSet.StringVarP(&cliOptions.HTTPDirectory, "http-directory", "hd", "", "directory with files to serve with http server"),
flagSet.StringVarP(&cliOptions.DefaultHTTPResponseFile, "default-http-response", "dhr", "", "file to serve for all http requests (takes priority over other options)"),
flagSet.BoolVarP(&cliOptions.DiskStorage, "disk", "ds", false, "disk based storage"),
flagSet.StringVarP(&cliOptions.DiskStoragePath, "disk-path", "dsp", "", "disk storage path"),
flagSet.StringVarP(&cliOptions.HeaderServer, "server-header", "csh", "", "custom value of Server header in response"),
Expand Down
2 changes: 2 additions & 0 deletions pkg/options/server_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type CLIServerOptions struct {
DisableUpdateCheck bool
NoVersionHeader bool
HeaderServer string
DefaultHTTPResponseFile string
}

func (cliServerOptions *CLIServerOptions) AsServerOptions() *server.Options {
Expand Down Expand Up @@ -93,5 +94,6 @@ func (cliServerOptions *CLIServerOptions) AsServerOptions() *server.Options {
EnableMetrics: cliServerOptions.EnableMetrics,
NoVersionHeader: cliServerOptions.NoVersionHeader,
HeaderServer: cliServerOptions.HeaderServer,
DefaultHTTPResponseFile: cliServerOptions.DefaultHTTPResponseFile,
}
}
30 changes: 24 additions & 6 deletions pkg/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
// HTTPServer is a http server instance that listens both
// TLS and Non-TLS based servers.
type HTTPServer struct {
options *Options
tlsserver http.Server
nontlsserver http.Server
customBanner string
staticHandler http.Handler
options *Options
tlsserver http.Server
nontlsserver http.Server
customBanner string
defaultResponse string
staticHandler http.Handler
}

type noopLogger struct {
Expand Down Expand Up @@ -63,12 +64,22 @@ func NewHTTPServer(options *Options) (*HTTPServer, error) {
// If custom index, read the custom index file and serve it.
// Supports {DOMAIN} placeholders.
if options.HTTPIndex != "" {
abs, _ := filepath.Abs(options.HTTPDirectory)
abs, _ := filepath.Abs(options.HTTPIndex)
gologger.Info().Msgf("Using custom server index: %s", abs)
if data, err := os.ReadFile(options.HTTPIndex); err == nil {
server.customBanner = string(data)
}
}
// If default response file is specified, read it and serve for all requests.
// This takes priority over all other response options.
// Supports {DOMAIN} placeholders.
if options.DefaultHTTPResponseFile != "" {
abs, _ := filepath.Abs(options.DefaultHTTPResponseFile)
gologger.Info().Msgf("Using default HTTP response file for all requests: %s", abs)
if data, err := os.ReadFile(options.DefaultHTTPResponseFile); err == nil {
server.defaultResponse = string(data)
}
}
router := &http.ServeMux{}
router.Handle("/", server.logger(server.corsMiddleware(http.HandlerFunc(server.defaultHandler))))
router.Handle("/register", server.corsMiddleware(server.authMiddleware(http.HandlerFunc(server.registerHandler))))
Expand Down Expand Up @@ -255,6 +266,13 @@ func (h *HTTPServer) defaultHandler(w http.ResponseWriter, req *http.Request) {
}

reflection := h.options.URLReflection(req.Host)

// If default response is set, serve it for all requests (highest priority)
if h.defaultResponse != "" {
_, _ = fmt.Fprint(w, strings.ReplaceAll(h.defaultResponse, "{DOMAIN}", domain))
return
}

if stringsutil.HasPrefixI(req.URL.Path, "/s/") && h.staticHandler != nil {
if h.options.DynamicResp && len(req.URL.Query()) > 0 {
values := req.URL.Query()
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type Options struct {
NoVersionHeader bool
// HeaderServer use custom string in HTTP response Server header instead of domain
HeaderServer string
// DefaultHTTPResponseFile is a file to serve for all HTTP requests (takes priority over other options)
DefaultHTTPResponseFile string

ACMEStore *acme.Provider
Stats *Metrics
Expand Down
Loading