-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtimer.go
More file actions
128 lines (100 loc) · 2.84 KB
/
timer.go
File metadata and controls
128 lines (100 loc) · 2.84 KB
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
package main
import (
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"time"
)
func runTimer(fuzzingPath string, timeout int) {
timerChan := make(chan os.Signal, 1)
interval := 1 * time.Second
var crashes int
var paths int
var vuln string
signal.Notify(timerChan, syscall.SIGINT, syscall.SIGTERM)
time.Sleep(interval)
for i := 0; i < timeout; i++ {
if _, err := os.Stat("/tmp/XSS"); errors.Is(err, os.ErrNotExist) {
// /tmp/XSS is not found
} else {
cmd := exec.Command("node", "bot.js", targetURL)
cmd.Start()
if i % 20 == 0{
data, err := os.Open("bot.log")
if err == nil {
byteValue, _ := ioutil.ReadAll(data)
for _, parsedURL := range strings.Split(string(byteValue), "\n") {
traversalMap[parsedURL] = true
}
}
for key, value := range traversalMap {
if !value {
cmd := exec.Command("node", "traversal_bot.js", key)
cmd.Start()
}
}
}
os.Remove("/tmp/XSS")
}
select {
case <-timerChan:
fmt.Println("\nInterrupt signal received. Exiting...")
return
default:
progress := float64(i) / float64(timeout) * 100
bar := strings.Repeat("=", int(float64(i) / float64(timeout) * 30))
spaces := strings.Repeat(" ", 30 - int(float64(i) / float64(timeout) * 30))
files, err := ioutil.ReadDir(fuzzingPath + "/output/crashes")
if err != nil {
panic(err)
}
for _, file := range files {
crashes = 0
if !file.IsDir() {
if startsWith(file.Name(), "vuln:") {
crashes++
vuln = strings.Split(strings.Split(file.Name(), ":")[1], ",")[0]
}
}
}
files, err = ioutil.ReadDir(fuzzingPath + "/output/queue")
if err != nil {
panic(err)
}
paths = 0
for _, file := range files {
if !file.IsDir() {
if startsWith(file.Name(), "id:") {
paths++
}
}
}
fmt.Print("\033[K")
if progress < 33 {
fmt.Printf(" [\033[31m%v>%v\033[0m][%ds/%ds %.2f%%] completed", bar, spaces, i, timeout, progress)
} else if progress < 66 {
fmt.Printf(" [\033[38;5;208m%v>%v\033[0m][%ds/%ds %.2f%%] completed", bar, spaces, i, timeout, progress)
} else if progress < 100 {
fmt.Printf(" [\033[33m%v>%v\033[0m][%ds/%ds %.2f%%] completed", bar, spaces, i, timeout, progress)
}
fmt.Printf(" found %d paths and total \033[32;5;3m%d crashes \033[31m%v\033[0m\r", paths, crashes, vuln)
if (configData.FirstCrash == true) && (1 <= crashes) {
goto FIRSTCRASH
}
time.Sleep(interval)
}
}
fmt.Printf(" [\033[32m==============================>\033[0m][%ds/%ds %.2f%%] completed", timeout, timeout, 100.0)
FIRSTCRASH:
termChan <- syscall.SIGTERM
fmt.Printf("\n")
fmt.Println("Task completed!\n")
}
func startsWith(str string, prefix string) bool {
return len(str) >= len(prefix) && str[:len(prefix)] == prefix
}