Skip to content

Instantly share code, notes, and snippets.

@markusthoemmes
Created April 20, 2020 12:23
Show Gist options
  • Save markusthoemmes/90800e40a4178de5aaae2cd6e18d865c to your computer and use it in GitHub Desktop.
Save markusthoemmes/90800e40a4178de5aaae2cd6e18d865c to your computer and use it in GitHub Desktop.
Basic Golang example for host spoofing on HTTP requests.
package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"net/http"
)
func main() {
client := &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return (&net.Dialer{}).DialContext(ctx, network, "127.0.0.1:80")
},
},
}
req, err := http.NewRequest("GET", "http://default-hello-world.default.example.com/test", nil)
if err != nil {
panic(err)
}
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment