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

Erorr reading body using DumpResponseHeadersAndRaw when proxy used #138

Closed
RamanaReddy0M opened this issue Apr 20, 2023 · 0 comments · Fixed by #139
Closed

Erorr reading body using DumpResponseHeadersAndRaw when proxy used #138

RamanaReddy0M opened this issue Apr 20, 2023 · 0 comments · Fixed by #139
Assignees
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@RamanaReddy0M
Copy link
Contributor

RamanaReddy0M commented Apr 20, 2023

When we read the http response body received via proxy, we get both an error and a response(not empty).

In such cases httputils.DumpResponseHeadersAndRaw(..) return an empty response instead actual response.

Example to reproduce

package main

import (
	"crypto/tls"
	"fmt"
	"net/http"
	"net/url"

	pdhttputil "github.com/projectdiscovery/utils/http"
)

func main() {
	// Set the proxy URL
	proxyURL := "http://127.0.0.1:8081" // Update with your actual Burp Suite proxy URL

	// Create a proxy URL object
	proxy, err := url.Parse(proxyURL)
	if err != nil {
		fmt.Println("Failed to parse proxy URL:", err)
		return
	}

	// Create a custom HTTP transport with proxy settings
	transport := &http.Transport{
		Proxy: http.ProxyURL(proxy),
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true, // Ignore SSL certificate verification (for Burp Suite proxy)
		},
	}

	// Create an HTTP client with the custom transport
	client := &http.Client{
		Transport: transport,
	}

	// Create an HTTP request
	req, err := http.NewRequest("GET", "https://www.youtube.com", nil)
	if err != nil {
		fmt.Println("Failed to create request:", err)
		return
	}

	// Send the HTTP request via the Burp Suite proxy
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Failed to send request via proxy:", err)
		return
	}
	defer resp.Body.Close()

	//##Expected Behaviour
	// Read the response body using ioutils
	//body, err := ioutil.ReadAll(resp.Body)

	//##Current Behaviour
	// Read the response using pdhttputils
	_, body, err := pdhttputil.DumpResponseHeadersAndRaw(resp)

	// Print the response body
	fmt.Println("Body: ", string(body))
	// Err
	fmt.Println("ERROR: ", err)

}

@RamanaReddy0M RamanaReddy0M self-assigned this Apr 20, 2023
@RamanaReddy0M RamanaReddy0M linked a pull request Apr 20, 2023 that will close this issue
@Mzack9999 Mzack9999 added Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. Status: Completed Nothing further to be done with this issue. Awaiting to be closed. labels Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Completed Nothing further to be done with this issue. Awaiting to be closed. Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants