forked from FiloSottile/Heartbleed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbleed_serve.go
137 lines (118 loc) · 2.74 KB
/
bleed_serve.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
//+build skip
package main
import (
"encoding/json"
"fmt"
bleed "github.com/FiloSottile/Heartbleed/bleed"
"log"
"net/http"
"net/url"
)
var PAYLOAD = []byte("heartbleed.filippo.io")
func defaultHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "http://filippo.io/Heartbleed", http.StatusFound)
}
func testHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hi there.")
}
type result struct {
Code int `json:"code"`
Data string `json:"data"`
Error string `json:"error"`
Host string `json:"host"`
}
func handleRequest(tgt *bleed.Target, w http.ResponseWriter, r *http.Request, skip bool) {
w.Header().Set("Access-Control-Allow-Origin", "*")
data, err := bleed.Heartbleed(tgt, PAYLOAD, skip)
var rc int
var errS string
if err == bleed.Safe || err == bleed.Closed {
rc = 1
} else if err != nil {
rc = 2
} else {
rc = 0
// _, err := bleed.Heartbleed(tgt, PAYLOAD)
// if err == nil {
// // Two VULN in a row
// rc = 0
// } else {
// // One VULN and one not
// _, err := bleed.Heartbleed(tgt, PAYLOAD)
// if err == nil {
// // 2 VULN on 3 tries
// rc = 0
// } else {
// // 1 VULN on 3 tries
// if err == bleed.Safe {
// rc = 1
// } else {
// rc = 2
// }
// }
// }
}
switch rc {
case 0:
log.Printf("%v (%v) - VULNERABLE [skip: %v]", tgt.HostIp, tgt.Service, skip)
case 1:
data = ""
log.Printf("%v (%v) - SAFE", tgt.HostIp, tgt.Service)
case 2:
data = ""
errS = err.Error()
if errS == "Please try again" {
log.Printf("%v (%v) - MISMATCH", tgt.HostIp, tgt.Service)
} else {
log.Printf("%v (%v) - ERROR [%v]", tgt.HostIp, tgt.Service, errS)
}
}
res := result{rc, data, errS, tgt.HostIp}
j, err := json.Marshal(res)
if err != nil {
log.Println("ERROR", err)
} else {
w.Write(j)
}
}
func bleedHandler(w http.ResponseWriter, r *http.Request) {
host := r.URL.Path[len("/bleed/"):]
tgt := bleed.Target{
HostIp: string(host),
Service: "https",
}
handleRequest(&tgt, w, r, true)
}
func bleedQueryHandler(w http.ResponseWriter, r *http.Request) {
q, ok := r.URL.Query()["u"]
if !ok || len(q) != 1 {
return
}
skip, ok := r.URL.Query()["skip"]
s := false
if ok && len(skip) == 1 {
s = true
}
tgt := bleed.Target{
HostIp: string(q[0]),
Service: "https",
}
u, err := url.Parse(tgt.HostIp)
if err == nil && u.Host != "" {
tgt.HostIp = u.Host
if u.Scheme != "" {
tgt.Service = u.Scheme
}
}
handleRequest(&tgt, w, r, s)
}
func main() {
http.HandleFunc("/", defaultHandler)
http.HandleFunc("/test", testHandler)
http.HandleFunc("/bleed/", bleedHandler)
http.HandleFunc("/bleed/query", bleedQueryHandler)
err := http.ListenAndServe(":80", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}