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

Added timeout option #107

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cli/commandline.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/vulncheck-oss/go-exploit/c2"
"github.com/vulncheck-oss/go-exploit/config"
"github.com/vulncheck-oss/go-exploit/output"
"github.com/vulncheck-oss/go-exploit/protocol"
)

// VulnCheck IPIntel data is shipped in single line JSON blobs. There is substantially more metadata, but
Expand Down Expand Up @@ -372,6 +373,8 @@ func remoteHostFlags(conf *config.Config, rhosts *string, rhostsFile *string, rp
// the Rport should be pre-configured to have a default value (see config.go:New())
flag.IntVar(&conf.Rport, "rport", conf.Rport, "The remote target's server port")
flag.StringVar(rports, "rports", "", "A comma delimited list of the remote target's server ports")
// generic all comms connection timeout
flag.IntVar(&protocol.GlobalCommTimeout, "timeout", 10, "The remote target's server port")
}

// command line flags for defining the local host.
Expand Down
19 changes: 17 additions & 2 deletions protocol/httphelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import (
"github.com/vulncheck-oss/go-exploit/transform"
)

// GlobalUA is the default User-Agent for all go-exploit comms.
var GlobalUA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36" +
"(KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.33"

// GlobalCommTimeout is the default timeout for all socket communications.
var GlobalCommTimeout = 10

// Returns a valid HTTP/HTTPS URL provided the given input.
func GenerateURL(rhost string, rport int, ssl bool, uri string) string {
url := ""
Expand Down Expand Up @@ -157,16 +161,27 @@ func SetRequestHeaders(req *http.Request, headers map[string]string) {

func CreateRequest(verb string, url string, payload string, followRedirect bool) (*http.Client, *http.Request, bool) {
var client *http.Client

if !followRedirect {
client = &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: time.Duration(GlobalCommTimeout) * time.Second,
}).Dial,
},
Timeout: time.Duration(GlobalCommTimeout) * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
} else {
client = &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
Dial: (&net.Dialer{
Timeout: time.Duration(GlobalCommTimeout) * time.Second,
}).Dial,
},
Timeout: time.Duration(GlobalCommTimeout) * time.Second,
}
}
req, err := http.NewRequest(verb, url, strings.NewReader(payload))
Expand Down
4 changes: 2 additions & 2 deletions protocol/tcpsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TCPConnect(host string, port int) (net.Conn, bool) {

// timeout long hanging connections
perHost := proxy.NewPerHost(dialer, proxy.Direct)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(GlobalCommTimeout)*time.Second)
defer cancel()
conn, err := perHost.DialContext(ctx, "tcp", target)
if err != nil {
Expand All @@ -61,7 +61,7 @@ func TCPConnect(host string, port int) (net.Conn, bool) {
}

// no proxy involved
conn, err := net.DialTimeout("tcp", target, 10*time.Second)
conn, err := net.DialTimeout("tcp", target, time.Duration(GlobalCommTimeout)*time.Second)
if err != nil {
output.PrintFrameworkError("Connection failed: " + err.Error())

Expand Down
Loading