-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwhoiz.go
190 lines (160 loc) · 4.01 KB
/
whoiz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
import (
"bytes"
"fmt"
"log"
"net"
"os"
"github.com/PuerkitoBio/goquery"
"github.com/Ullaakut/nmap"
"github.com/likexian/whois-go"
"github.com/likexian/whois-parser-go"
"github.com/urfave/cli"
"github.com/valyala/fasthttp"
)
type httpResp struct {
title string
desc string
code int
}
//////////
//WHOIZ //
//////////
func main() {
app := cli.NewApp()
app.Name = "whoiz"
app.Usage = "because whois is loud af!\n\t example: whoiz domain.com"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "verbose",
Value: "",
},
}
app.Action = func(c *cli.Context) error {
domainName := string(c.Args().Get(0))
fmt.Println("Looking Up... \t ", domainName)
whoisResult, err := whois.Whois(domainName)
result, err := whoisparser.Parse(whoisResult)
printTitle("Domain Reg:")
if err == nil {
fmt.Println("\tRegistrant: " + result.Registrant.Name)
fmt.Println("\tEmail: " + result.Registrant.Email)
fmt.Println("\tRegistrar: " + result.Registrar.RegistrarName + " [#" + result.Registrar.RegistrarID + "]")
fmt.Println("\tDomain Status: " + result.Registrar.DomainStatus)
fmt.Println("\tCreated Date: " + result.Registrar.CreatedDate)
fmt.Println("\tExpiration Date:" + result.Registrar.ExpirationDate)
} else {
fmt.Println("\tNo whois information available for " + domainName + " \n")
}
printTitle("HTTPS:")
res := fetchPage(domainName)
if res.code == 0 {
fmt.Println("\tPage Title: \t")
fmt.Println("\tResponse: \t")
} else {
fmt.Println("\tPage Title: \t", res.title)
fmt.Println("\tPage Desc: \t", res.desc)
fmt.Println("\tResponse: \t", res.code)
}
printTitle("Host(s):")
ips, err := net.LookupIP(domainName)
if err != nil {
fmt.Println("[!]")
} else if len(ips) == 0 {
fmt.Println("No host record found.")
}
for _, ip := range ips {
fmt.Println("\t\033[1m" + ip.String() + "\033[0m")
scanPorts(ip.String())
}
printTitle("NS record(s):")
nss, err := net.LookupNS(domainName)
if err != nil {
fmt.Println("[!]")
} else if len(nss) == 0 {
fmt.Println("No NS records found.")
}
for _, ns := range nss {
fmt.Println("\t", ns.Host)
}
printTitle("MX record(s):")
mxs, err := net.LookupMX(domainName)
if err != nil {
fmt.Println("[!]")
} else if len(mxs) == 0 {
fmt.Println("No MX records found.")
}
for _, mx := range mxs {
fmt.Println("\t", mx.Pref, " \t", mx.Host)
}
printTitle("TXT record(s):")
txts, err := net.LookupTXT(domainName)
if err != nil {
fmt.Println("[!]")
} else if len(txts) == 0 {
fmt.Println("No TXT records found.")
}
for _, txt := range txts {
fmt.Println("\t", txt)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func printTitle(str string) {
fmt.Println("\n\033[1m" + str + "\033[0m")
}
func scanPorts(ip string) {
scanner, err := nmap.NewScanner(
nmap.WithTargets(ip),
nmap.WithFastMode(),
)
if err != nil {
log.Fatalf("Unable to initialize scanner: %v", err)
}
result, err := scanner.Run()
if err != nil {
log.Fatalf("unable to run nmap scan: %v", err)
}
for _, host := range result.Hosts {
if len(host.Ports) == 0 || len(host.Addresses) == 0 {
continue
}
fmt.Println("\t Port Summary: ", host.Addresses[0], " => ")
for _, port := range host.Ports {
if port.State.String() != "closed" {
fmt.Printf("\t\t %d/%s \t%s \t%s\n", port.ID, port.Protocol, port.State, port.Service.Name)
}
}
}
}
func fetchPage(domain string) httpResp {
resp := httpResp{
title: " - ",
desc: " - ",
code: 0,
}
url := string("http://" + domain)
rc, body, _ := fasthttp.Get(nil, url)
resp.code = rc
r := bytes.NewReader(body)
doc, err := goquery.NewDocumentFromReader(r)
if err == nil {
title := doc.Find("title").Text()
if title != "" {
resp.title = title
}
doc.Find("meta").Each(func(i int, s *goquery.Selection) {
if name, _ := s.Attr("name"); name == "description" {
desc, _ := s.Attr("content")
if desc != "" {
resp.desc = desc
}
}
})
}
return resp
}