Skip to content

Commit

Permalink
Merge pull request #11 from trickest/remove-folder-output
Browse files Browse the repository at this point in the history
Remove folder output and file split
  • Loading branch information
PolovinaD authored Feb 25, 2022
2 parents e6c57a3 + c8122e2 commit aa347db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 40 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ Usage of mksub:
Input domain
-df string
Input domain file, one domain per line
-file string
Output file(s) name (default "output.txt")
-l int
Subdomain level to generate (default 1)
-nf int
Number of files to split the output into (faster with multiple files) (default 1)
-o string
Output folder (stdout will be used when omitted)
Output file (stdout will be used when omitted)
-r string
Regex to filter words from wordlist file
-silent
Expand Down
49 changes: 14 additions & 35 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
roundChan "mksub/round"
"os"
"os/signal"
"path"
"regexp"
"strconv"
"strings"
Expand All @@ -19,6 +18,7 @@ import (
const (
bufferSizeMB = 100
maxWorkingThreads = 100000
numberOfFiles = 1
)

var (
Expand All @@ -28,16 +28,14 @@ var (
)

var (
domain string
domainFile string
wordlist string
regex string
nf int
level int
workers int
outputFolder string
outputFile string
silent bool
domain string
domainFile string
wordlist string
regex string
level int
workers int
outputFile string
silent bool

workerThreadMax = make(chan struct{}, maxWorkingThreads)
done = make(chan struct{})
Expand Down Expand Up @@ -135,7 +133,7 @@ func spawnWriters(number int) {
extension := "." + fileSplit[len(fileSplit)-1]
fileName = strings.TrimSuffix(fileName, extension) + "-" + strconv.Itoa(i) + extension
}
file, err := os.Create(path.Join(outputFolder, fileName))
file, err := os.Create(fileName)
if err != nil {
fmt.Println(err)
fmt.Println("Couldn't open file to write output!")
Expand Down Expand Up @@ -228,10 +226,8 @@ func main() {
flag.StringVar(&wordlist, "w", "", "Wordlist file")
flag.StringVar(&regex, "r", "", "Regex to filter words from wordlist file")
flag.IntVar(&level, "l", 1, "Subdomain level to generate")
flag.StringVar(&outputFolder, "o", "", "Output folder (stdout will be used when omitted)")
flag.StringVar(&outputFile, "file", "output.txt", "Output file(s) name")
flag.StringVar(&outputFile, "o", "", "Output file (stdout will be used when omitted)")
flag.IntVar(&workers, "t", 100, "Number of threads for every subdomain level")
flag.IntVar(&nf, "nf", 1, "Number of files to split the output into (faster with multiple files)")
flag.BoolVar(&silent, "silent", true, "Skip writing generated subdomains to stdout (faster)")
flag.Parse()

Expand All @@ -249,30 +245,13 @@ func main() {
os.Exit(0)
}

if outputFolder == "" {
if outputFile == "" {
silent = false
} else {
dirPath := strings.Split(strings.Trim(outputFolder, "/"), "/")
toMerge := ""
for _, dir := range dirPath {
toMerge = path.Join(toMerge, dir)
dirInfo, err := os.Stat(toMerge)
dirExists := !os.IsNotExist(err) && dirInfo.IsDir()

if !dirExists {
err = os.Mkdir(toMerge, 0755)
if err != nil {
fmt.Println(err)
fmt.Println("Couldn't create a directory to store outputs!")
os.Exit(0)
}
}
}
}

prepareDomains()
readWordlistFile()
spawnWriters(nf)
spawnWriters(numberOfFiles)

for _, d := range inputDomains {
wg.Add(1)
Expand All @@ -282,6 +261,6 @@ func main() {
}

wg.Wait()
closeWriters(nf)
closeWriters(numberOfFiles)
wgWrite.Wait()
}

0 comments on commit aa347db

Please sign in to comment.