Skip to content

Commit

Permalink
Merge branch 'http-proxy'
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Jun 17, 2024
2 parents 6871690 + c53586e commit fb99643
Show file tree
Hide file tree
Showing 12 changed files with 888 additions and 724 deletions.
27 changes: 6 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,11 @@ module github.com/zmap/zgrab2
go 1.22

require (
<<<<<<< HEAD
github.com/hdm/jarm-go v0.0.7
github.com/prometheus/client_golang v1.19.0
github.com/sirupsen/logrus v1.9.3
github.com/zmap/zcrypto v0.0.0-20231219022726-a1f61fb1661c
github.com/zmap/zflags v1.4.0-beta.1.0.20200204220219-9d95409821b6
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81
golang.org/x/net v0.22.0
golang.org/x/sys v0.18.0
golang.org/x/text v0.14.0
=======
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/hdm/jarm-go v0.0.7
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rabbitmq/amqp091-go v1.9.0
github.com/sirupsen/logrus v1.9.0
github.com/zmap/zcrypto v0.0.0-20230310154051-c8b263fd8300
Expand All @@ -30,22 +17,20 @@ require (
golang.org/x/sys v0.20.0
golang.org/x/text v0.15.0
google.golang.org/protobuf v1.33.0 // indirect
>>>>>>> 9dc4b8af853d23bf55340c69d5d3ff2a4f1a4806
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/yaml.v2 v2.4.0
)

require golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/weppos/publicsuffix-go v0.30.2 // indirect
github.com/zmap/rc2 v0.0.0-20190804163417-abaa70531248 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
512 changes: 16 additions & 496 deletions go.sum

Large diffs are not rendered by default.

206 changes: 0 additions & 206 deletions modules/amqp/scanner.go

This file was deleted.

2 changes: 1 addition & 1 deletion modules/upnp/upnp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (cfg *upnpTester) getScanner() (*Scanner, error) {
flags.Method = "M-SEARCH"
flags.Man = "ssdp:discover"
flags.St = "upnp:rootdevice"
flags.UserAgent = "Mozilla/5.0 UPnP/2.0 zgrab/0.1.6"
flags.UserAgent = "Mozilla/5.0 UPnP zgrab/0.1.6"
flags.Port = uint(cfg.port)
flags.Timeout = 1 * time.Second

Expand Down
91 changes: 91 additions & 0 deletions modules/webproxy/request/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package request

import (
"fmt"
"strings"

"github.com/zmap/zgrab2/lib/http"
)

type HttpRequestBuilder interface {
setUrl(url string)
setMethod(method string) error
setHeaders(headers http.Header)
Build(body string) (*http.Request, error)
}

func NewHttpRequestBuilder(method, url string, headers http.Header) (HttpRequestBuilder, error) {
builder := new(httpProxyRequestBuilder)

err := builder.setMethod(method)
if err != nil {
return nil, err
}

builder.setUrl(url)
builder.setHeaders(headers)

return builder, nil
}

type httpProxyRequestBuilder struct {
method string
url string
headers http.Header
}

func (builder *httpProxyRequestBuilder) setUrl(url string) {
if len(url) > 0 {
builder.url = fmt.Sprintf("http://%s", url)
return
}
builder.url = "/"
}

func (builder *httpProxyRequestBuilder) setMethod(method string) error {
allowed := []string{"GET", "POST"} // This is sufficient for proxies
for _, val := range allowed {
if val == method {
builder.method = method
return nil
}
}
return fmt.Errorf("method not allowed: %s", method)
}

func (builder *httpProxyRequestBuilder) setHeaders(headers http.Header) {
builder.headers = http.Header{
"Accept": {"*/*"},
"Proxy-Connection": {"close"},
"Cache-Control": {"no-store"},
}

if headers == nil {
return
}

for k, v := range headers {
builder.headers[k] = v
}
}

func (builder *httpProxyRequestBuilder) Build(body string) (*http.Request, error) {

// Add the body
var b *strings.Reader
if len(body) > 0 {
b = strings.NewReader(body)
}

// Create the request
req, err := http.NewRequest(builder.method, builder.url, b)
if err != nil {
return nil, err
}

// Add the headers
// The constructor does not add any header.
req.Header = builder.headers

return req, nil
}
Loading

0 comments on commit fb99643

Please sign in to comment.