Replies: 2 comments
-
@aroly Thanks for opening this issue. The scenario that you are describing can be done also with the standard library as you can see at the following link. package main
import (
"fmt"
"log"
"net/http"
"github.com/projectdiscovery/rawhttp"
)
func main() {
webserver := "http://localhost:8000"
hostname := "bar.com"
fmt.Println("Target server: " + webserver)
fmt.Println("Hostname: " + hostname)
clientOptions := rawhttp.DefaultOptions
clientOptions.AutomaticHostHeader = false
clientOptions.FollowRedirects = false
client := rawhttp.NewClient(clientOptions)
req, err := http.NewRequest("GET", webserver, nil)
req.Method = "GET"
req.Header.Set("Host", " "+hostname)
req.Host = hostname
req.Header.Set("User-Agent", " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36")
req.Header.Set("Connection", " close")
req.Header.Set("Accept", " */*")
req.Proto = "HTTP/1.1"
//fmt.Printf("%+v\n\n", req)
resp, err := client.Do(req)
if err != nil {
fmt.Printf("Error while requesting %s with %s\n", webserver, hostname)
log.Fatalf("Error: %s", err)
}
fmt.Printf("Status: %s, Content-Length: %d\n", resp.Status, int64(resp.ContentLength))
fmt.Printf("\n%s / HTTP/1.1\n", req.Method)
for name, values := range req.Header {
// Loop over all values for the name.
for _, value := range values {
fmt.Printf("%s:%s\n", name, value)
}
}
} I get this output (where you can see the
|
Beta Was this translation helpful? Give feedback.
-
Hello, Thanks for pointing out that I can do what I want using the standard library. For the record, I finally found out why I was getting an error in some specific cases, I'm gonna explain it here in case someone else has the same issue. My idea was to send a HTTP request to, let's say, Most of the time, even with HTTP My issue came from the fact that the webserver was sending back a HTTP 302 to To avoid this case, I used the trick I found here: https://stackoverflow.com/questions/23297520/how-can-i-make-the-go-http-client-not-follow-redirects-automatically
|
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm currently facing a weird issue with one specific case when using the lib to send "malformed" HTTP request. My idea is to send a request to a specific HTTP(S) server, but with a different "Host" header in the HTTP request, to test for Host header attacks. Most of the time, this works well, but I sometimes receive this issue when running the code.
In this case, the hostname I want to use is not known by the DNS, but this should not be a problem. And it woks perfectly in other cases. I attached the code I use as txt (it's crappy, but it's the first time I write something in Go :)).
test.go.txt
Beta Was this translation helpful? Give feedback.
All reactions