Skip to content

Commit c051973

Browse files
authored
Merge pull request #7 from pry0cc/urls
Added —urls option
2 parents d85ab13 + 406cf48 commit c051973

File tree

6 files changed

+562
-7
lines changed

6 files changed

+562
-7
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

data/ex3/uber-dnsx.json

Lines changed: 517 additions & 0 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ import (
88
"github.com/n0ncetonic/nmapxml"
99
"log"
1010
"os"
11+
"strings"
1112
)
1213

1314
func main() {
1415
var inputArg = flag.String("x", "", "Nmap XML Input File (Required)")
1516
var dnsxArg = flag.String("dnsx", "", "dnsx -resp output data (Optional)")
1617
var vhostRep = flag.Bool("vhost", false, "Use dnsx data to insert vhosts (Optional)")
18+
var urlArg = flag.Bool("urls", false, "Guess HTTP URLs from input (Optional)")
1719
var outputArg = flag.String("o", "", "Output filename (Optional)")
1820
flag.Parse()
1921

2022
input := *inputArg
2123
output := *outputArg
2224
dnsx := *dnsxArg
2325
vhost := *vhostRep
26+
urls := *urlArg
2427

2528
if input == "" {
2629
flag.PrintDefaults()
2730
os.Exit(1)
2831
}
2932

30-
results := ParseNmap(input, dnsx, vhost)
33+
results := ParseNmap(input, dnsx, vhost, urls)
3134

3235
for _, line := range results {
3336
fmt.Println(line)
@@ -67,7 +70,7 @@ func Unique(slice []string) []string {
6770
return uniqSlice
6871
}
6972

70-
func ParseNmap(input string, dnsx string, vhost bool) []string {
73+
func ParseNmap(input string, dnsx string, vhost bool, urls bool) []string {
7174
/* ParseNmap parses a Nmap XML file */
7275
var index map[string][]string
7376
var output []string
@@ -92,21 +95,37 @@ func ParseNmap(input string, dnsx string, vhost bool) []string {
9295
for _, portData := range *host.Ports.Port {
9396
if portData.State.State == "open" {
9497
portID := portData.PortID
98+
service := portData.Service.Name
9599

96100
if vhost {
97101
for _, ipp := range index {
98102
domains := ipp
99103

100104
for _, dom := range domains {
101-
//fmt.Println(dom + ":" + portID)
102-
line := dom + ":" + portID
103-
output = append(output, line)
105+
line := ""
106+
if urls {
107+
line = GenUrl(dom, portID, service)
108+
} else {
109+
line = dom + ":" + portID
110+
}
111+
112+
if line != "" {
113+
output = append(output, line)
114+
}
104115
}
105116
}
106117

107118
} else {
108-
line := ipAddr + ":" + portID
109-
output = append(output, line)
119+
line := ""
120+
if urls {
121+
line = GenUrl(ipAddr, portID, service)
122+
} else {
123+
line = ipAddr + ":" + portID
124+
}
125+
126+
if line != "" {
127+
output = append(output, line)
128+
}
110129
//fmt.Println(ipAddr + ":" + portID)
111130
}
112131
}
@@ -118,6 +137,25 @@ func ParseNmap(input string, dnsx string, vhost bool) []string {
118137
return uniq
119138
}
120139

140+
func GenUrl(host string, port string, service string) string {
141+
/* GenURl generates a URL for a given sequence */
142+
url := ""
143+
if service == "http" || service == "https" {
144+
url = service + "://" + host
145+
} else if strings.Contains(service, "http") {
146+
if strings.Contains(port, "80") {
147+
service = "http"
148+
} else if strings.Contains(port, "443") {
149+
service = "https"
150+
} else {
151+
service = "http"
152+
}
153+
url = service + "://" + host + ":" + port
154+
}
155+
156+
return url
157+
}
158+
121159
func ParseDnsx(filename string) map[string][]string {
122160
/* ParseDnsx parses a DNSX JSON file */
123161
var data = map[string][]string{}

0 commit comments

Comments
 (0)