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 6 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 @@ -1303,6 +1303,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?

Copy link

Choose a reason for hiding this comment

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

I know you weren't asking me, but my 2c anyway is that the old format with , was poorly (if at all) documented and I had to work it out from the source. I don't think anyone knows about it / is using it

So if the new format host[ip] could be documented somewhere then the new format is probably better

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe we can go with the new format and +1 to document it.

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 @@ -1515,6 +1538,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 h, ip, err := parseVhostInput(target); err == nil {
results <- httpx.Target{Host: h, CustomIP: ip}
}
default:
results <- httpx.Target{Host: target}
}
Expand All @@ -1529,9 +1556,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