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

feature: custom timeout option #70

Merged
merged 1 commit into from
May 12, 2021
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
5 changes: 2 additions & 3 deletions command/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/signal"
"strings"
"time"

"github.com/spf13/cobra"
"github.com/v-byte-cpu/sx/command/log"
Expand All @@ -19,6 +18,7 @@ func init() {
dockerCmd.Flags().StringVarP(&cliIPPortFileFlag, "file", "f", "", "set JSONL file with ip/port pairs to scan")
dockerCmd.Flags().StringVar(&cliProtoFlag, "proto", "", "set protocol to use, http is used by default; only http or https are valid")
dockerCmd.Flags().IntVarP(&cliWorkerCountFlag, "workers", "w", defaultWorkerCount, "set workers count")
dockerCmd.Flags().DurationVarP(&cliTimeoutFlag, "timeout", "t", defaultTimeout, "set request timeout")
rootCmd.AddCommand(dockerCmd)
}

Expand Down Expand Up @@ -61,8 +61,7 @@ var dockerCmd = &cobra.Command{
}

func newDockerScanEngine(ctx context.Context) scan.EngineResulter {
// TODO custom dataTimeout
scanner := docker.NewScanner(cliProtoFlag, docker.WithDataTimeout(10*time.Second))
scanner := docker.NewScanner(cliProtoFlag, docker.WithDataTimeout(cliTimeoutFlag))
results := scan.NewResultChan(ctx, 1000)
return scan.NewScanEngine(newIPPortGenerator(), scanner, results, scan.WithScanWorkerCount(cliWorkerCountFlag))
}
5 changes: 2 additions & 3 deletions command/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/signal"
"strings"
"time"

"github.com/spf13/cobra"
"github.com/v-byte-cpu/sx/command/log"
Expand All @@ -19,6 +18,7 @@ func init() {
elasticCmd.Flags().StringVarP(&cliIPPortFileFlag, "file", "f", "", "set JSONL file with ip/port pairs to scan")
elasticCmd.Flags().StringVar(&cliProtoFlag, "proto", "", "set protocol to use, http is used by default; only http or https are valid")
elasticCmd.Flags().IntVarP(&cliWorkerCountFlag, "workers", "w", defaultWorkerCount, "set workers count")
elasticCmd.Flags().DurationVarP(&cliTimeoutFlag, "timeout", "t", defaultTimeout, "set request timeout")
rootCmd.AddCommand(elasticCmd)
}

Expand Down Expand Up @@ -61,8 +61,7 @@ var elasticCmd = &cobra.Command{
}

func newElasticScanEngine(ctx context.Context) scan.EngineResulter {
// TODO custom dataTimeout
scanner := elastic.NewScanner(cliProtoFlag, elastic.WithDataTimeout(5*time.Second))
scanner := elastic.NewScanner(cliProtoFlag, elastic.WithDataTimeout(cliTimeoutFlag))
results := scan.NewResultChan(ctx, 1000)
return scan.NewScanEngine(newIPPortGenerator(), scanner, results, scan.WithScanWorkerCount(cliWorkerCountFlag))
}
2 changes: 2 additions & 0 deletions command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var (
cliIPProtocolFlag string
cliIPFlagsFlag string
cliWorkerCountFlag int
cliTimeoutFlag time.Duration

cliInterface *net.Interface
cliSrcIP net.IP
Expand All @@ -135,6 +136,7 @@ const (
cliHTTPSProtoFlag = "https"

defaultWorkerCount = 100
defaultTimeout = 5 * time.Second
)

var (
Expand Down
6 changes: 3 additions & 3 deletions command/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func init() {
socksCmd.Flags().StringVarP(&cliPortsFlag, "ports", "p", "", "set ports to scan")
socksCmd.Flags().StringVarP(&cliIPPortFileFlag, "file", "f", "", "set JSONL file with ip/port pairs to scan")
socksCmd.Flags().IntVarP(&cliWorkerCountFlag, "workers", "w", defaultWorkerCount, "set workers count")
socksCmd.Flags().DurationVarP(&cliTimeoutFlag, "timeout", "t", 2*time.Second, "set connect and data timeout")
rootCmd.AddCommand(socksCmd)
}

Expand Down Expand Up @@ -53,10 +54,9 @@ var socksCmd = &cobra.Command{
}

func newSOCKSScanEngine(ctx context.Context) scan.EngineResulter {
// TODO custom dialTimeout, dataTimeout
scanner := socks5.NewScanner(
socks5.WithDialTimeout(2*time.Second),
socks5.WithDataTimeout(2*time.Second))
socks5.WithDialTimeout(cliTimeoutFlag),
socks5.WithDataTimeout(cliTimeoutFlag))
results := scan.NewResultChan(ctx, 1000)
return scan.NewScanEngine(newIPPortGenerator(), scanner, results, scan.WithScanWorkerCount(cliWorkerCountFlag))
}