forked from FiloSottile/Heartbleed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bleed.go
60 lines (48 loc) · 1.3 KB
/
bleed.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
package main
import (
bleed "github.com/FiloSottile/Heartbleed/bleed"
"flag"
"fmt"
"log"
"net/url"
"os"
)
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 tgt bleed.Target
flag.StringVar(&tgt.Service, "service", "https", fmt.Sprintf("Specify a service name to test (using STARTTLS if necessary). \n\t\tBesides HTTPS, currently supported services are: \n\t\t%s", bleed.Services))
flag.Parse()
if flag.NArg() < 1 {
usage()
}
tgt.HostIp = flag.Arg(0)
u, err := url.Parse(tgt.HostIp)
if err == nil && u.Host != "" {
tgt.HostIp = u.Host
if u.Scheme != "" {
tgt.Service = u.Scheme
}
}
out, err := bleed.Heartbleed(&tgt, []byte("heartbleed.filippo.io"))
if err == bleed.Safe {
log.Printf("%v - SAFE", tgt.HostIp)
os.Exit(0)
} else if err != nil {
log.Printf("%v - ERROR: %v", tgt.HostIp, err)
os.Exit(2)
} else {
log.Printf("%v\n", string(out))
log.Printf("%v - VULNERABLE", tgt.HostIp)
os.Exit(1)
}
}