Skip to content

Commit

Permalink
handle multiple output case
Browse files Browse the repository at this point in the history
  • Loading branch information
dogancanbakir committed Feb 1, 2024
1 parent db34c66 commit b64375e
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions pkg/massdns/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/shuffledns/internal/store"
"github.com/projectdiscovery/shuffledns/pkg/parser"
folderutil "github.com/projectdiscovery/utils/folder"
"github.com/remeh/sizedwaitgroup"
"github.com/rs/xid"
)
Expand All @@ -42,7 +43,8 @@ func (c *Client) Process() error {
defer shstore.Close()

// Set the correct target file
massDNSOutput := filepath.Join(c.config.TempDir, xid.New().String())
tmpDir := c.config.TempDir
massDNSOutput := filepath.Join(tmpDir, xid.New().String())
if c.config.MassdnsRaw != "" {
massDNSOutput = c.config.MassdnsRaw
}
Expand All @@ -59,7 +61,7 @@ func (c *Client) Process() error {

gologger.Info().Msgf("Started parsing massdns output\n")

err = c.parseMassDNSOutput(massDNSOutput, shstore)
err = c.parseMassDNSOutputDir(tmpDir, shstore)
if err != nil {
return fmt.Errorf("could not parse massdns output: %w", err)
}
Expand Down Expand Up @@ -105,8 +107,8 @@ func (c *Client) runMassDNS(output string, store *store.Store) error {
return nil
}

func (c *Client) parseMassDNSOutput(output string, store *store.Store) error {
massdnsOutput, err := os.Open(output)
func (c *Client) parseMassDNSOutputFile(tmpFile string, store *store.Store) error {
massdnsOutput, err := os.Open(tmpFile)
if err != nil {
return fmt.Errorf("could not open massdns output file: %w", err)
}
Expand Down Expand Up @@ -138,6 +140,22 @@ func (c *Client) parseMassDNSOutput(output string, store *store.Store) error {
return nil
}

func (c *Client) parseMassDNSOutputDir(tmpDir string, store *store.Store) error {
tmpFiles, err := folderutil.GetFiles(tmpDir)
if err != nil {
return fmt.Errorf("could not open massdns output directory: %w", err)
}

for _, tmpFile := range tmpFiles {
err = c.parseMassDNSOutputFile(tmpFile, store)
if err != nil {
return fmt.Errorf("could not parse massdns output: %w", err)
}
}

return nil
}

func (c *Client) filterWildcards(st *store.Store) error {
// Start to work in parallel on wildcards
wildcardWg := sizedwaitgroup.New(c.config.WildcardsThreads)
Expand Down

0 comments on commit b64375e

Please sign in to comment.