forked from FiloSottile/Heartbleed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bleed_serve.go
75 lines (66 loc) · 1.49 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
//+build skip
package main
import (
bleed "github.com/FiloSottile/Heartbleed/bleed"
"encoding/json"
"fmt"
"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"`
}
func bleedHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
host := r.URL.Path[len("/bleed/"):]
u, err := url.Parse(host)
if err == nil && u.Host != "" {
host = u.Host
}
tgt := bleed.Target{
HostIp: string(host),
Service: "https",
}
data, err := bleed.Heartbleed(&tgt, PAYLOAD)
var rc int
var errS string
if err == bleed.Safe {
rc = 1
data = []byte("")
log.Printf("%v - SAFE", host)
} else if err != nil {
rc = 2
data = []byte("")
errS = err.Error()
log.Printf("%v - ERROR", host)
} else {
rc = 0
log.Printf("%v - VULNERABLE", host)
}
res := result{rc, string(data), errS}
j, err := json.Marshal(res)
if err != nil {
log.Println("ERROR", err)
} else {
w.Write(j)
}
}
func main() {
http.HandleFunc("/", defaultHandler)
http.HandleFunc("/test", testHandler)
http.HandleFunc("/bleed/", bleedHandler)
err := http.ListenAndServe(":80", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}