-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
81 lines (58 loc) · 1.66 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
76
77
78
79
80
81
package main
import (
"bufio"
"encoding/json"
"fmt"
"net/http"
//https://golang.org/pkg/net/http/pprof/
//http://localhost:8082/debug/pprof/goroutine?debug=1
_ "net/http/pprof"
"os"
"runtime"
"text/template"
"github.com/asalih/ca/ca"
)
var Manager *ca.Manager
func main() {
startingGs := runtime.NumGoroutine()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
t, err := template.ParseFiles("index.html")
if err != nil {
fmt.Fprintf(w, "Unable to load template")
}
t.Execute(w, nil)
})
http.HandleFunc("/vulns", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
if Manager == nil {
json.NewEncoder(w).Encode(nil)
return
}
json.NewEncoder(w).Encode(Manager.Attacker.FoundVulnerabilities)
})
http.HandleFunc("/attack", func(w http.ResponseWriter, r *http.Request) {
if Manager != nil && !Manager.IsFinished() {
w.Write([]byte("Attack in progress"))
return
}
Manager = ca.NewManager(r.URL.Query().Get("attackUrl"))
go Manager.CrawlAndAttack()
w.Write([]byte("Attack started!"))
})
http.HandleFunc("/state", func(w http.ResponseWriter, r *http.Request) {
if Manager != nil && Manager.IsFinished() {
w.Write([]byte("finished"))
return
}
w.Write([]byte("na"))
})
go http.ListenAndServe("localhost:8082", nil)
endingGs := runtime.NumGoroutine()
fmt.Println("Number of goroutines before:", startingGs)
fmt.Println("Number of goroutines after :", endingGs)
fmt.Println("Waiting an input for exit: ")
input := bufio.NewScanner(os.Stdin)
input.Scan()
fmt.Println(input.Text())
}