这是indexloc提供的服务,不要输入任何密码
Skip to content
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
4 changes: 2 additions & 2 deletions v2/pkg/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type ResolutionPool struct {

// HostEntry defines a host with the source
type HostEntry struct {
Host string `json:"host"`
Source string `json:"source"`
Host string
Source string
}

// Result contains the result for a host resolution
Expand Down
8 changes: 4 additions & 4 deletions v2/pkg/runner/enumerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ func (r *Runner) EnumerateSingleDomain(ctx context.Context, domain string, outpu
var err error
for _, w := range outputs {
if r.options.HostIP {
err = outputter.WriteHostIP(foundResults, w)
err = outputter.WriteHostIP(domain, foundResults, w)
} else {
if r.options.RemoveWildcard {
err = outputter.WriteHostNoWildcard(foundResults, w)
err = outputter.WriteHostNoWildcard(domain, foundResults, w)
} else {
if r.options.CaptureSources {
err = outputter.WriteSourceHost(sourceMap, w)
err = outputter.WriteSourceHost(domain, sourceMap, w)
} else {
err = outputter.WriteHost(uniqueMap, w)
err = outputter.WriteHost(domain, uniqueMap, w)
}
}
}
Expand Down
58 changes: 36 additions & 22 deletions v2/pkg/runner/outputter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ type OutPutter struct {
JSON bool
}

type jsonResult struct {
type jsonSourceResult struct {
Host string `json:"host"`
Input string `json:"input"`
Source string `json:"source"`
}

type jsonSourceIPResult struct {
Host string `json:"host"`
IP string `json:"ip"`
Input string `json:"input"`
Source string `json:"source"`
}

type jsonSourceResult struct {
type jsonSourcesResult struct {
Host string `json:"host"`
Input string `json:"input"`
Sources []string `json:"sources"`
}

Expand Down Expand Up @@ -64,17 +72,17 @@ func (o *OutPutter) createFile(filename string, appendtoFile bool) (*os.File, er
}

// WriteHostIP writes the output list of subdomain to an io.Writer
func (o *OutPutter) WriteHostIP(results map[string]resolve.Result, writer io.Writer) error {
func (o *OutPutter) WriteHostIP(input string, results map[string]resolve.Result, writer io.Writer) error {
var err error
if o.JSON {
err = writeJSONHostIP(results, writer)
err = writeJSONHostIP(input, results, writer)
} else {
err = writePlainHostIP(results, writer)
err = writePlainHostIP(input, results, writer)
}
return err
}

func writePlainHostIP(results map[string]resolve.Result, writer io.Writer) error {
func writePlainHostIP(_ string, results map[string]resolve.Result, writer io.Writer) error {
bufwriter := bufio.NewWriter(writer)
sb := &strings.Builder{}

Expand All @@ -96,14 +104,15 @@ func writePlainHostIP(results map[string]resolve.Result, writer io.Writer) error
return bufwriter.Flush()
}

func writeJSONHostIP(results map[string]resolve.Result, writer io.Writer) error {
func writeJSONHostIP(input string, results map[string]resolve.Result, writer io.Writer) error {
encoder := jsoniter.NewEncoder(writer)

var data jsonResult
var data jsonSourceIPResult

for _, result := range results {
data.Host = result.Host
data.IP = result.IP
data.Input = input
data.Source = result.Source

err := encoder.Encode(&data)
Expand All @@ -115,27 +124,27 @@ func writeJSONHostIP(results map[string]resolve.Result, writer io.Writer) error
}

// WriteHostNoWildcard writes the output list of subdomain with nW flag to an io.Writer
func (o *OutPutter) WriteHostNoWildcard(results map[string]resolve.Result, writer io.Writer) error {
func (o *OutPutter) WriteHostNoWildcard(input string, results map[string]resolve.Result, writer io.Writer) error {
hosts := make(map[string]resolve.HostEntry)
for host, result := range results {
hosts[host] = resolve.HostEntry{Host: result.Host, Source: result.Source}
}

return o.WriteHost(hosts, writer)
return o.WriteHost(input, hosts, writer)
}

// WriteHost writes the output list of subdomain to an io.Writer
func (o *OutPutter) WriteHost(results map[string]resolve.HostEntry, writer io.Writer) error {
func (o *OutPutter) WriteHost(input string, results map[string]resolve.HostEntry, writer io.Writer) error {
var err error
if o.JSON {
err = writeJSONHost(results, writer)
err = writeJSONHost(input, results, writer)
} else {
err = writePlainHost(results, writer)
err = writePlainHost(input, results, writer)
}
return err
}

func writePlainHost(results map[string]resolve.HostEntry, writer io.Writer) error {
func writePlainHost(_ string, results map[string]resolve.HostEntry, writer io.Writer) error {
bufwriter := bufio.NewWriter(writer)
sb := &strings.Builder{}

Expand All @@ -153,11 +162,15 @@ func writePlainHost(results map[string]resolve.HostEntry, writer io.Writer) erro
return bufwriter.Flush()
}

func writeJSONHost(results map[string]resolve.HostEntry, writer io.Writer) error {
func writeJSONHost(input string, results map[string]resolve.HostEntry, writer io.Writer) error {
encoder := jsoniter.NewEncoder(writer)

var data jsonSourceResult
for _, result := range results {
err := encoder.Encode(result)
data.Host = result.Host
data.Input = input
data.Source = result.Source
err := encoder.Encode(data)
if err != nil {
return err
}
Expand All @@ -166,23 +179,24 @@ func writeJSONHost(results map[string]resolve.HostEntry, writer io.Writer) error
}

// WriteSourceHost writes the output list of subdomain to an io.Writer
func (o *OutPutter) WriteSourceHost(sourceMap map[string]map[string]struct{}, writer io.Writer) error {
func (o *OutPutter) WriteSourceHost(input string, sourceMap map[string]map[string]struct{}, writer io.Writer) error {
var err error
if o.JSON {
err = writeSourceJSONHost(sourceMap, writer)
err = writeSourceJSONHost(input, sourceMap, writer)
} else {
err = writeSourcePlainHost(sourceMap, writer)
err = writeSourcePlainHost(input, sourceMap, writer)
}
return err
}

func writeSourceJSONHost(sourceMap map[string]map[string]struct{}, writer io.Writer) error {
func writeSourceJSONHost(input string, sourceMap map[string]map[string]struct{}, writer io.Writer) error {
encoder := jsoniter.NewEncoder(writer)

var data jsonSourceResult
var data jsonSourcesResult

for host, sources := range sourceMap {
data.Host = host
data.Input = input
keys := make([]string, 0, len(sources))
for source := range sources {
keys = append(keys, source)
Expand All @@ -197,7 +211,7 @@ func writeSourceJSONHost(sourceMap map[string]map[string]struct{}, writer io.Wri
return nil
}

func writeSourcePlainHost(sourceMap map[string]map[string]struct{}, writer io.Writer) error {
func writeSourcePlainHost(_ string, sourceMap map[string]map[string]struct{}, writer io.Writer) error {
bufwriter := bufio.NewWriter(writer)
sb := &strings.Builder{}

Expand Down