-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcensys.go
94 lines (73 loc) · 1.87 KB
/
censys.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
/*
Copyright (c) 2017, AverageSecurityGuy
# All rights reserved.
View Censys data about an IP address, a domain name or a TLS certificate.
Usage:
$ go run censys.go -d domain
$ go run censys.go -i ip
$ go run censys.go -c sha256
*/
package main
import (
"os"
"fmt"
"flag"
"bytes"
"net/http"
"io/ioutil"
"encoding/json"
)
const base = "https://censys.io/api/v1/view"
const uid = ""
const secret = ""
func check(e error) {
if e != nil {
fmt.Printf("Error: %s\n", e.Error())
}
}
func lookup(data_type, value string) {
url := fmt.Sprintf("%s/%s/%s", base, data_type, value)
fmt.Printf("[*] Looking up %s\n", url)
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
req.SetBasicAuth(uid, secret)
resp, err := client.Do(req)
check(err)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
check(err)
if resp.StatusCode == 404 {
fmt.Println("[-] File not found.")
} else if resp.StatusCode == 429 {
fmt.Println("[-] Rate limit exceeded. Please wait and try again.")
} else if resp.StatusCode == 500 {
fmt.Println("[-] Internal Server Error.")
} else {
var pp bytes.Buffer
err := json.Indent(&pp, body, "", " ")
check(err)
fmt.Println(string(pp.Bytes()))
}
}
func main() {
var d string
var i string
var c string
flag.StringVar(&d, "d", "", "Domain Name")
flag.StringVar(&i, "i", "", "IP Address")
flag.StringVar(&c, "c", "", "SHA256 Fingerprint")
flag.Parse()
// We should only have one flag set
if flag.NFlag() != 1 {
fmt.Println("[-] Only one of the flags -d, -i, or -c may be set.")
fmt.Println("[-] Use -h or --help for more details.")
os.Exit(0)
}
if d != "" {
lookup("websites", d)
} else if i != "" {
lookup("ipv4", i)
} else {
lookup("certificates", c)
}
}