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

fix stdin parsing #2021

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -1302,6 +1302,29 @@ func (r *Runner) RunEnumeration() {
}
}

func parseVhostInput(input string) (hostname, ip string, err error) {
// Expecting format: host[ip]
if !strings.Contains(input, "[") || !strings.HasSuffix(input, "]") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we also should keep supporting the old format:

target,vhost

since we are introducing a breaking change. What do you think?

return "", "", fmt.Errorf("invalid input format: %s", input)
}

// Split the input into hostname and IP parts
parts := strings.SplitN(input, "[", 2)
if len(parts) != 2 {
return "", "", fmt.Errorf("invalid input format: %s", input)
}

hostname = parts[0]
ip = strings.TrimSuffix(parts[1], "]")

// Validate that both hostname and IP are not empty
if hostname == "" || ip == "" {
return "", "", fmt.Errorf("invalid input format: %s", input)
}

return hostname, ip, nil
}

func logFilteredErrorPage(fileName, url string) {
dir := filepath.Dir(fileName)
if !fileutil.FolderExists(dir) {
Expand Down Expand Up @@ -1514,6 +1537,10 @@ func (r *Runner) targets(hp *httpx.HTTPX, target string) chan httpx.Target {
case !stringsutil.HasPrefixAny(target, "http://", "https://") && stringsutil.ContainsAny(target, ","):
idxComma := strings.Index(target, ",")
results <- httpx.Target{Host: target[idxComma+1:], CustomHost: target[:idxComma]}
case stringsutil.ContainsAny(target, "[", "]") && r.options.VHostInput:
if _, ip, err := parseVhostInput(target); err == nil {
results <- httpx.Target{Host: ip}
}
default:
results <- httpx.Target{Host: target}
}
Expand All @@ -1528,9 +1555,6 @@ func (r *Runner) analyze(hp *httpx.HTTPX, protocol string, target httpx.Target,
}
retried := false
retry:
if scanopts.VHostInput && target.CustomHost == "" {
return Result{Input: origInput}
}
URL, err := r.parseURL(target.Host)
if err != nil {
return Result{URL: target.Host, Input: origInput, Err: err}
Expand Down
Loading