Skip to content

Commit

Permalink
url input, documentation, and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lanrat committed Dec 14, 2017
1 parent 96a431a commit a061d59
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ This tool was designed to be used for host name enumeration via SSL certificates
## Usage
```
Usage of ./certgraph: [OPTION]... HOST...
https://github.com/lanrat/certgraph
https://github.com/lanrat/certgraph
OPTIONS:
-cdn
include certificates from CDNs
include certificates from CDNs
-ct-expired
include expired certificates in certificate transparancy search
-ct-subdomains
include sub-domains in certificate transparancy search
include sub-domains in certificate transparancy search
-depth uint
maximum BFS depth to go (default 5)
maximum BFS depth to go (default 5)
-details
print details about the domains crawled
print details about the domains crawled
-driver string
driver to use [http, smtp, google, crtsh] (default "http")
driver to use [http, smtp, google, crtsh] (default "http")
-json
print the graph as json, can be used for graph in web UI
print the graph as json, can be used for graph in web UI
-parallel uint
number of certificates to retrieve in parallel (default 10)
number of certificates to retrieve in parallel (default 10)
-save string
save certs to folder in PEM formate
save certs to folder in PEM formate
-timeout uint
tcp timeout in seconds (default 10)
tcp timeout in seconds (default 10)
-verbose
verbose logging
verbose logging
-version
print version and exit
print version and exit
```

## Drivers
Expand Down
33 changes: 29 additions & 4 deletions certgraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"flag"
"fmt"
"net"
"net/url"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -106,7 +108,15 @@ func main() {
graph.Verbose = config.verbose

config.timeout = time.Duration(*timeoutPtr) * time.Second
startDomains := flag.Args()
startDomains := make([]string, 0, 1)

for _, domain := range flag.Args() {
d := cleanHostName(strings.ToLower(domain))
if len(d) > 0 {
startDomains = append(startDomains, d)
v("clean", d)
}
}

switch config.driver {
case "google":
Expand Down Expand Up @@ -134,9 +144,6 @@ func main() {
return
}

for i, domain := range startDomains {
startDomains[i] = strings.ToLower(domain)
}
if len(config.savePath) > 0 {
err := os.MkdirAll(config.savePath, 0777)
if err != nil {
Expand Down Expand Up @@ -313,5 +320,23 @@ func visitSSL(node *graph.DomainNode) {
certnode, _ = dgraph.LoadOrStoreCert(certnode)
node.VisitedCert = certnode.Fingerprint
}
}

// sanitize the input to accept urls
func cleanHostName(host string) string {
u, err := url.Parse(host)
if err != nil {
v(err)
return ""
}
host = u.Host

if strings.Contains(host, ":") {
host, _, err = net.SplitHostPort(host)
if err != nil {
v(err)
return ""
}
}
return host
}
18 changes: 9 additions & 9 deletions driver/ssl/smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func (d *smtpDriver) GetCert(host string) (status.DomainStatus, *graph.CertNode,
}

func GetMX(domain string) ([]string, error) {
domains := make([]string, 0, 5)
mx, err := net.LookupMX(domain)
if err != nil {
return domains, err
}
for _, v := range mx {
domains = append(domains, v.Host)
}
return domains, nil
domains := make([]string, 0, 5)
mx, err := net.LookupMX(domain)
if err != nil {
return domains, err
}
for _, v := range mx {
domains = append(domains, v.Host)
}
return domains, nil
}
2 changes: 1 addition & 1 deletion graph/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewDomainNode(domain string, depth uint) *DomainNode {
func (d *DomainNode) String() string {
cert := ""
// CT
if len(d.CTCerts) > 0 {
if len(d.CTCerts) > 0 {
for i := range d.CTCerts {
cert = fmt.Sprintf("%s %s", cert, d.CTCerts[i].HexString())
}
Expand Down

0 comments on commit a061d59

Please sign in to comment.