Skip to content

Commit 99ed61e

Browse files
authored
Merge pull request #4 from pry0cc/outputfile
added dedupe, added output file, added outputfile flag
2 parents e6bb1f0 + 159fcc2 commit 99ed61e

File tree

2 files changed

+60
-10
lines changed

2 files changed

+60
-10
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Binaries are available for most platforms and archectectures in the [releases pa
2727
nmap -T4 1.1.1.1 8.8.8.8 -oX file.xml
2828
2929
tew -x file.xml
30-
tew -x file.xml | tee output.txt
30+
tew -x file.xml -o output.txt
3131
tew -x file.xml | httpx -json -o http.json
3232
```
3333

@@ -47,12 +47,13 @@ tew -x nmap.xml -dnsx dns.json --vhost | httpx -json -o http.json
4747
- [x] Add Arm64 for Darwin to Build
4848
- [x] Use proper flags library
4949
- [x] Add ability to import and use dnsx JSON & text output files - working on it!
50-
- [ ] Clean up DNSX Parsing module and sort unique
51-
- [ ] Add output text file as option
50+
- [x] Clean up DNSX Parsing module and sort unique
51+
- [x] Add output text file as option
5252
- [ ] Test on Windows, Linux & Mac for cross-compatibility
5353

5454
# Credit
5555
- @hakluke - Thank you man for helping me fix that dumb bug :)
5656
- @vay3t - Go Help
5757
- @BruceEdiger - Go Help
5858
- @mortensonsam - Go help!!
59+
- https://www.golangprograms.com - A lot of the code here is copy-pasted from the internet, at the time of writing, my go skills are copy-paste :P And that's ok if it works, right?

main.go

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ import (
1111
)
1212

1313
func main() {
14-
var vhostRep = flag.Bool("vhost", false, "Use dnsx data to insert vhosts (Optional)")
15-
var dnsxArg = flag.String("dnsx", "", "dnsx -resp output data (Optional)")
1614
var inputArg = flag.String("x", "", "Nmap XML Input File (Required)")
15+
var dnsxArg = flag.String("dnsx", "", "dnsx -resp output data (Optional)")
16+
var vhostRep = flag.Bool("vhost", false, "Use dnsx data to insert vhosts (Optional)")
17+
var outputArg = flag.String("o", "", "Output filename (Optional)")
1718
flag.Parse()
1819

1920
input := *inputArg
21+
output := *outputArg
2022
dnsx := *dnsxArg
2123
vhost := *vhostRep
2224

@@ -25,11 +27,50 @@ func main() {
2527
os.Exit(1)
2628
}
2729

28-
ParseNmap(input, dnsx, vhost)
30+
results := ParseNmap(input, dnsx, vhost)
31+
32+
for _, line := range results {
33+
fmt.Println(line)
34+
}
35+
36+
if output != "" {
37+
file, err := os.OpenFile(output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
38+
39+
if err != nil {
40+
log.Fatalf("failed creating file: %s", err)
41+
}
42+
43+
datawriter := bufio.NewWriter(file)
44+
45+
for _, data := range results {
46+
_, _ = datawriter.WriteString(data + "\n")
47+
}
48+
49+
datawriter.Flush()
50+
file.Close()
51+
}
52+
2953
}
3054

31-
func ParseNmap(input string, dnsx string, vhost bool) {
55+
func Unique(slice []string) []string {
56+
// create a map with all the values as key
57+
uniqMap := make(map[string]struct{})
58+
for _, v := range slice {
59+
uniqMap[v] = struct{}{}
60+
}
61+
62+
// turn the map keys into a slice
63+
uniqSlice := make([]string, 0, len(uniqMap))
64+
for v := range uniqMap {
65+
uniqSlice = append(uniqSlice, v)
66+
}
67+
return uniqSlice
68+
}
69+
70+
func ParseNmap(input string, dnsx string, vhost bool) []string {
71+
/* ParseNmap parses a Nmap XML file */
3272
var index map[string][]string
73+
var output []string
3374
r, _ := nmapxml.Readfile(input)
3475

3576
if _, err := os.Stat(input); err != nil {
@@ -57,21 +98,28 @@ func ParseNmap(input string, dnsx string, vhost bool) {
5798
domains := ipp
5899

59100
for _, dom := range domains {
60-
fmt.Println(dom + ":" + portID)
101+
//fmt.Println(dom + ":" + portID)
102+
line := dom + ":" + portID
103+
output = append(output, line)
61104
}
62105
}
63106

64107
} else {
65-
fmt.Println(ipAddr + ":" + portID)
108+
line := ipAddr + ":" + portID
109+
output = append(output, line)
110+
//fmt.Println(ipAddr + ":" + portID)
66111
}
67112
}
68113
}
69114
}
70115
}
116+
117+
uniq := Unique(output)
118+
return uniq
71119
}
72120

73121
func ParseDnsx(filename string) map[string][]string {
74-
/* ParseDnsx parses a DNSX JSON file*/
122+
/* ParseDnsx parses a DNSX JSON file */
75123
var data = map[string][]string{}
76124
file, err := os.Open(filename)
77125
if err != nil {
@@ -90,6 +138,7 @@ func ParseDnsx(filename string) map[string][]string {
90138
for _, record := range aRecords {
91139
ip = record.(string)
92140
}
141+
93142
data[ip] = append(data[ip], host)
94143
}
95144

0 commit comments

Comments
 (0)