Created
April 20, 2020 12:23
-
-
Save markusthoemmes/90800e40a4178de5aaae2cd6e18d865c to your computer and use it in GitHub Desktop.
Basic Golang example for host spoofing on HTTP requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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