Skip to content
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

add dynamic headers , status and delay to work with http-directory #747

Merged
merged 2 commits into from
Feb 21, 2024
Merged
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
40 changes: 30 additions & 10 deletions pkg/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import (
"bytes"
"encoding/base64"
"crypto/tls"
"encoding/base64"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -256,6 +256,26 @@

reflection := h.options.URLReflection(req.Host)
if stringsutil.HasPrefixI(req.URL.Path, "/s/") && h.staticHandler != nil {
if h.options.DynamicResp && len(req.URL.Query()) > 0 {
values := req.URL.Query()
if headers := values["header"]; len(headers) > 0 {
for _, header := range headers {
if headerParts := strings.SplitN(header, ":", 2); len(headerParts) == 2 {
w.Header().Add(headerParts[0], headerParts[1])
}
}
}
if delay := values.Get("delay"); delay != "" {
if parsed, err := strconv.Atoi(delay); err == nil {
time.Sleep(time.Duration(parsed) * time.Second)
}
}
if status := values.Get("status"); status != "" {
if parsed, err := strconv.Atoi(status); err == nil {
w.WriteHeader(parsed)
}
}
}
h.staticHandler.ServeHTTP(w, req)
} else if req.URL.Path == "/" && reflection == "" {
if h.customBanner != "" {
Expand All @@ -272,7 +292,7 @@
fmt.Fprintf(w, "<data>%s</data>", reflection)
w.Header().Set("Content-Type", "application/xml")
} else {
if h.options.DynamicResp && (len(req.URL.Query()) > 0 || stringsutil.HasPrefixI(req.URL.Path, "/b64_body:")) {
if h.options.DynamicResp && (len(req.URL.Query()) > 0 || stringsutil.HasPrefixI(req.URL.Path, "/b64_body:")) {
writeResponseFromDynamicRequest(w, req)
return
}
Expand All @@ -293,11 +313,11 @@
values := req.URL.Query()

if stringsutil.HasPrefixI(req.URL.Path, "/b64_body:") {
firstindex := strings.Index(req.URL.Path, "/b64_body:")
lastIndex := strings.LastIndex(req.URL.Path, "/")
firstindex := strings.Index(req.URL.Path, "/b64_body:")
lastIndex := strings.LastIndex(req.URL.Path, "/")

decodedBytes, _ := base64.StdEncoding.DecodeString(req.URL.Path[firstindex+10:lastIndex])
_, _ = w.Write(decodedBytes)
decodedBytes, _ := base64.StdEncoding.DecodeString(req.URL.Path[firstindex+10 : lastIndex])
_, _ = w.Write(decodedBytes)
Dismissed Show dismissed Hide dismissed

}
if headers := values["header"]; len(headers) > 0 {
Expand All @@ -319,10 +339,10 @@
_, _ = w.Write([]byte(body))
}

if b64_body := values.Get("b64_body"); b64_body != "" {
decodedBytes, _ := base64.StdEncoding.DecodeString(string([]byte(b64_body)))
_, _ = w.Write(decodedBytes)
}
if b64_body := values.Get("b64_body"); b64_body != "" {
decodedBytes, _ := base64.StdEncoding.DecodeString(string([]byte(b64_body)))
_, _ = w.Write(decodedBytes)
Dismissed Show dismissed Hide dismissed
}
}

// RegisterRequest is a request for client registration to interactsh server.
Expand Down
Loading