diff --git a/v2/go.mod b/v2/go.mod index 9df52194..1c90069e 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -61,6 +61,7 @@ require ( golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d golang.org/x/oauth2 v0.0.0-20210817223510-7df4dd6e12ab golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect + golang.org/x/text v0.3.6 google.golang.org/appengine v1.6.7 // indirect gopkg.in/yaml.v2 v2.4.0 ) @@ -116,7 +117,6 @@ require ( github.com/ysmood/goob v0.3.0 // indirect github.com/zclconf/go-cty v1.8.4 // indirect go.etcd.io/bbolt v1.3.5 // indirect - golang.org/x/text v0.3.6 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/protobuf v1.26.0 // indirect gopkg.in/corvus-ch/zbase32.v1 v1.0.0 // indirect diff --git a/v2/pkg/protocols/http/request.go b/v2/pkg/protocols/http/request.go index 4a884b91..31672935 100644 --- a/v2/pkg/protocols/http/request.go +++ b/v2/pkg/protocols/http/request.go @@ -433,6 +433,14 @@ func (r *Request) executeRequest(reqURL string, request *generatedRequest, previ } finalEvent := make(output.InternalEvent) + // Decode gbk response content-types + if contentTypes, ok := resp.Header["Content-Type"]; ok && len(contentTypes) > 0 && strings.Contains(contentTypes[0], "gbk") && strings.Contains(contentTypes[0], "gb2312") { + dumpedResponse, err = decodegbk(dumpedResponse) + if err != nil { + return errors.Wrap(err, "could not store in project file") + } + } + outputEvent := r.responseToDSLMap(resp, reqURL, matchedURL, tostring.UnsafeToString(dumpedRequest), tostring.UnsafeToString(dumpedResponse), tostring.UnsafeToString(data), headersToString(resp.Header), duration, request.meta) if i := strings.LastIndex(hostname, ":"); i != -1 { hostname = hostname[:i] diff --git a/v2/pkg/protocols/http/utils.go b/v2/pkg/protocols/http/utils.go index 95a27e7e..bb12b5a6 100644 --- a/v2/pkg/protocols/http/utils.go +++ b/v2/pkg/protocols/http/utils.go @@ -13,6 +13,8 @@ import ( "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators" "github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/tostring" "github.com/projectdiscovery/rawhttp" + "golang.org/x/text/encoding/simplifiedchinese" + "golang.org/x/text/transform" ) // dumpResponseWithRedirectChain dumps a http response with the @@ -122,3 +124,14 @@ func handleDecompression(resp *http.Response, bodyOrig []byte) (bodyDec []byte, } return bodyDec, nil } + +// decodegbk converts GBK to UTF-8 +func decodegbk(s []byte) ([]byte, error) { + I := bytes.NewReader(s) + O := transform.NewReader(I, simplifiedchinese.GBK.NewDecoder()) + d, e := ioutil.ReadAll(O) + if e != nil { + return nil, e + } + return d, nil +}