-
Notifications
You must be signed in to change notification settings - Fork 17
/
terminator.js
77 lines (62 loc) · 1.88 KB
/
terminator.js
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
class Terminator{
constructor(process,program){
this.terminatedCount=0;
this.terminated=false;
this.workerCount=0;
//register signal handlers
process.once('SIGINT', function (code) {
Terminator.prototype.graceful()
});
process.once('SIGTERM', function (code) {
Terminator.prototype.graceful()
});
this.outputfile = program.output
this.url = program.url
}
terminate(){
this.graceful(false);
if(!this.terminated){
this.terminated=true
this.browser.close()
}
}
register(thread){
this.workerCount+=1;
}
graceful(bTerminate=true){
console.log('\nExiting....')
if(this.outputfile){
if(!pendingOutput.length){
console.log('No vulnerabilities found, not creating an output file.')
if(bTerminate){
process.exit(1)
}else{
return
}
}
//there were results and output pending, write it in json format
var result = {}
baseUrl = this.url.replace(/^http(s)?:\/\//, '')
baseUrl = baseUrl.replace(/\/.*$/, '')
result.host = baseUrl
result.fuzzTarget = this.url
result.host_ip = remoteAddr
result.port = remotePort
result.source = 'puff-fuzzer'
result.found = []
for(var i=0;i<pendingOutput.length;i++){
result.found.push(pendingOutput[i])
}
var data = JSON.stringify(result);
fs.writeFileSync(this.outputfile, data);
}
if(bTerminate){
process.exit(1)
}else{
return
}
}
}
module.exports = {
Terminator:Terminator
}