-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.js
executable file
·120 lines (111 loc) · 4.15 KB
/
runner.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
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
#!/usr/bin/env node
const commandLineArgs = require('command-line-args');
const commandLineUsage = require('command-line-usage');
const Netsparker = require('./netsparker');
const cmdOptions = [
{ name: 'userid', alias: 'u', type: String },
{ name: 'apitoken', alias: 't', type: String },
{ name: 'profilename', alias: 'p', type: String },
{ name: 'targetsite', alias: 's', type: String },
{ name: 'junit', alias: 'j', type: String },
{ name: 'report', alias: 'r', type: Boolean },
{ name: 'help', alias: 'h', type: Boolean }
]
const sections = [
{
header: 'Netsparker Scan Runner',
content: 'Run a scan against your Netsparker Cloud instance using a configured profile. Can optionally wait for the report.'
},
{
header: 'Options',
optionList: [
{
name: 'userid',
typeLabel: '{underline userid}',
description: 'The user id from your Netsparker Account'
},
{
name: 'apitoken',
typeLabel: '{underline apitoken}',
description: 'The api token from your Netsparker Account'
},
{
name: 'profilename',
typeLabel: '{underline profilename}',
description: 'The profile name saved in your Netsparker Account'
},
{
name: 'targetsite',
typelabel: '{underline targeturl}',
description: 'The target url you want to run against'
},
{
name: 'report',
typelabel: 'true/false (defaults: true)',
description: 'If you want to wait around for the report (true) or to fire and forget (false)'
},
{
name: 'junit',
typelabel: 'junit export location/name',
description: 'If you want to generate a junit report, enter the file name and location here'
},
{
name: 'help',
description: 'Print this usage guide'
}
]
}
]
async function run() {
try {
const options = commandLineArgs(cmdOptions)
if(options.help) {
const usage = commandLineUsage(sections)
console.log(usage)
} else {
if(!(options.userid)) {
console.error("--userid is a required argument");
return;
}
if(!(options.apitoken)) {
console.error("--apitoken is a required argument");
return;
}
if(!(options.profilename)) {
console.error("--profilename is a required argument");
return;
}
if(!(options.targetsite)) {
console.error("--targetsite is a required argument");
return;
}
if(options.report === undefined) {
options.report = true;
}
if(!(options.junit) && options.report == false) {
console.error("You cannot specify a --junit location and set --report to false");
return;
}
const netsparker = new Netsparker(options.userid, options.apitoken, options.profilename, options.targetsite);
console.info("Starting scan...");
const scanId = await netsparker.scan();
console.info("Scan complete");
if(options.report) {
await netsparker.waitForScanToComplete(scanId);
const scanResults = await netsparker.scanResults(scanId);
console.table(scanResults);
if(options.junit) {
console.log("Generating jUnit report...");
netsparker.createJunitTestReport(scanResults, options.junit);
console.log("jUnit report generated");
}
} else {
console.log("Check the Netsparker Cloud portal for the status and outcome of your scan.");
return;
}
}
} catch(e) {
console.error(e);
}
}
run();