-
-
Notifications
You must be signed in to change notification settings - Fork 463
/
main.go
75 lines (63 loc) · 1.59 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"net/url"
"os"
"github.com/FiloSottile/Heartbleed/heartbleed"
)
var usageMessage = `This is a tool for detecting OpenSSL Heartbleed vulnerability (CVE-2014-0160).
Usage: %s [flags] server_name[:port]
The default port is 443 (HTTPS).
If a URL is supplied in server_name, it will be parsed to extract the host, but not the protocol.
The following flags are recognized:
`
func usage() {
fmt.Fprintf(os.Stderr, usageMessage, os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
func main() {
var (
service = flag.String("service", "https", fmt.Sprintf(
`Specify a service name to test (using STARTTLS if necessary).
Besides HTTPS, currently supported services are:
%s`, heartbleed.Services))
check_cert = flag.Bool("check-cert", false, "check the server certificate")
)
flag.Parse()
if flag.NArg() < 1 {
usage()
}
tgt := &heartbleed.Target{
Service: *service,
HostIp: flag.Arg(0),
}
// Parse the host out of URLs
u, err := url.Parse(tgt.HostIp)
if err == nil && u.Host != "" {
tgt.HostIp = u.Host
if u.Scheme != "" {
tgt.Service = u.Scheme
}
}
out, err := heartbleed.Heartbleed(tgt,
[]byte("github.com/FiloSottile/Heartbleed"), !(*check_cert))
if err == heartbleed.Safe {
log.Printf("%v - SAFE", tgt.HostIp)
os.Exit(0)
} else if err != nil {
if err.Error() == "Please try again" {
log.Printf("%v - TRYAGAIN: %v", tgt.HostIp, err)
os.Exit(2)
} else {
log.Printf("%v - ERROR: %v", tgt.HostIp, err)
os.Exit(2)
}
} else {
log.Printf("%v\n", out)
log.Printf("%v - VULNERABLE", tgt.HostIp)
os.Exit(1)
}
}