@sectester/runner 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +166 -0
- package/package.json +63 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/IssueFound.d.ts +7 -0
- package/src/lib/IssueFound.js +12 -0
- package/src/lib/IssueFound.js.map +1 -0
- package/src/lib/SecRunner.d.ts +15 -0
- package/src/lib/SecRunner.js +60 -0
- package/src/lib/SecRunner.js.map +1 -0
- package/src/lib/SecScan.d.ts +15 -0
- package/src/lib/SecScan.js +50 -0
- package/src/lib/SecScan.js.map +1 -0
- package/src/lib/SecScanOptions.d.ts +2 -0
- package/src/lib/SecScanOptions.js +3 -0
- package/src/lib/SecScanOptions.js.map +1 -0
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.js +8 -0
- package/src/lib/index.js.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Bright Security
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @sectester/runner
|
|
2
|
+
|
|
3
|
+
[](https://codeclimate.com/github/NeuraLegion/sectester-js/maintainability)
|
|
4
|
+
[](https://codeclimate.com/github/NeuraLegion/sectester-js/test_coverage)
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
Run scanning for vulnerabilities just from your unit tests on CI phase.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i -s @sectester/runner
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Step-by-step guide
|
|
17
|
+
|
|
18
|
+
### Configure SDK
|
|
19
|
+
|
|
20
|
+
To start writing tests, first obtain a Bright token, which is required for the access to Bright API. More info about [setting up an API key](https://docs.brightsec.com/docs/manage-your-personal-account#manage-your-personal-api-keys-authentication-tokens).
|
|
21
|
+
|
|
22
|
+
Then put obtained token into `BRIGHT_TOKEN` environment variable to make it accessible by default [`EnvCredentialProvider`](https://github.com/NeuraLegion/sectester-js/tree/master/packages/core#envcredentialprovider).
|
|
23
|
+
|
|
24
|
+
> Refer to `@sectester/core` package [documentation](https://github.com/NeuraLegion/sectester-js/tree/master/packages/core#credentials) for the details on alternative ways of configuring credential providers.
|
|
25
|
+
|
|
26
|
+
Once it is done, create a configuration object. Single required option is Bright `hostname` domain you are going to use, e.g. `app.neuralegion.com` as the main one:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { Configuration } from '@sectester/core';
|
|
30
|
+
|
|
31
|
+
const configuration = new Configuration({ hostname: 'app.neuralegion.com' });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Setup runner
|
|
35
|
+
|
|
36
|
+
To set up a runner, create `SecRunner` instance passing a previously created configuration as follows:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { Configuration } from '@sectester/core';
|
|
40
|
+
import { SecRunner } from '@sectester/runner';
|
|
41
|
+
|
|
42
|
+
const configuration = new Configuration({ hostname: 'app.neuralegion.com' });
|
|
43
|
+
const runner = new SecRunner(configuration);
|
|
44
|
+
|
|
45
|
+
// or
|
|
46
|
+
|
|
47
|
+
const runner2 = new SecRunner({ hostname: 'app.neuralegion.com' });
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
After that, you have to initialize a `SecRunner` instance:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
await runner.init();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The runner is now ready to perform your tests, but you have to create a scan.
|
|
57
|
+
|
|
58
|
+
To dispose a runner, you just need to call the `clear` method:
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
await runner.clear();
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Starting scan
|
|
65
|
+
|
|
66
|
+
To start scanning your application, first you have to create a `SecScan` instance, as shown below:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const scan = runner.createScan({ tests: [TestType.XSS] });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Below you will find a list of parameters that can be used to configure a `Scan`:
|
|
73
|
+
|
|
74
|
+
| Option | Description |
|
|
75
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
76
|
+
| `tests` | The list of tests to be performed against the target application. [Learn more about tests](https://docs.brightsec.com/docs/vulnerability-guide) |
|
|
77
|
+
| `smart` | Minimize scan time by using automatic smart decisions regarding parameter skipping, detection phases, etc. Enabled by default. |
|
|
78
|
+
| `skipStaticParams` | Use an advanced algorithm to automatically determine if a parameter has any effect on the target system's behavior when changed, and skip testing such static parameters. Enabled by default. |
|
|
79
|
+
| `poolSize` | Sets the maximum concurrent requests for the scan, to control the load on your server. By default, `10`. |
|
|
80
|
+
| `attackParamLocations` | Defines which part of the request to attack. By default, `body`, `query`, and `fragment`. |
|
|
81
|
+
| `slowEpTimeout` | Skip entry-points that take longer to respond than specified ms value. By default, 1000ms. |
|
|
82
|
+
| `targetTimeout` | Measure timeout responses from the target application globally, and stop the scan if the target is unresponsive for longer than the specified time. By default, 5min. |
|
|
83
|
+
| `name` | The scan name. The method and hostname by default, e.g. `GET example.com`. |
|
|
84
|
+
|
|
85
|
+
Finally, run a scan against your application:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
await scan.run({
|
|
89
|
+
method: 'POST',
|
|
90
|
+
url: 'https://localhost:8000/api/orders',
|
|
91
|
+
body: { subject: 'Test', body: "<script>alert('xss')</script>" }
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The `run` method takes a single argument (for details, see [here](https://github.com/NeuraLegion/sectester-js/tree/master/packages/scan#defining-a-target-for-attack)), and returns promise that is resolved if scan finishes without any vulnerability found, and is rejected otherwise (on founding issue that meets threshold, on timeout, on scanning error).
|
|
96
|
+
|
|
97
|
+
If any vulnerabilities are found, they will be pretty printed to stdout or stderr (depending on severity) by [reporter](https://github.com/NeuraLegion/sectester-js/tree/master/packages/reporter).
|
|
98
|
+
|
|
99
|
+
By default, each found issue will cause the scan to stop. To control this behavior you can set a severity threshold using the `threshold` method:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
scan.threshold(Severity.HIGH);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Now found issues with severity lower than `HIGH` will not cause the scan to stop.
|
|
106
|
+
|
|
107
|
+
Sometimes either due to scan configuration issues or target misbehave, the scan might take much more time than you expect.
|
|
108
|
+
In this case, you can provide a timeout (in milliseconds) for specifying maximum scan running time:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
scan.timeout(30000);
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
In that case after 30 seconds, if the scan isn't finishing or finding any vulnerability, it will throw an error.
|
|
115
|
+
|
|
116
|
+
### Usage sample
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { SecRunner, SecScan } from '@sectester/runner';
|
|
120
|
+
import { Severity, TestType } from '@sectester/scan';
|
|
121
|
+
|
|
122
|
+
describe('/api', () => {
|
|
123
|
+
let runner!: SecRunner;
|
|
124
|
+
let scan!: SecScan;
|
|
125
|
+
|
|
126
|
+
beforeEach(async () => {
|
|
127
|
+
runner = new SecRunner({ hostname: 'app.neuralegion.com' });
|
|
128
|
+
|
|
129
|
+
await runner.init();
|
|
130
|
+
|
|
131
|
+
scan = runner
|
|
132
|
+
.createScan({ tests: [TestType.XSS] })
|
|
133
|
+
.threshold(Severity.MEDIUM) // i. e. ignore LOW severity issues
|
|
134
|
+
.timeout(300000); // i. e. fail if last longer than 5 minutes
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
afterEach(async () => {
|
|
138
|
+
await runner.clear();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe('/orders', () => {
|
|
142
|
+
it('should not have persistent xss', async () => {
|
|
143
|
+
await scan.run({
|
|
144
|
+
method: 'POST',
|
|
145
|
+
url: 'https://localhost:8000/api/orders',
|
|
146
|
+
body: { subject: 'Test', body: "<script>alert('xss')</script>" }
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should not have reflective xss', async () => {
|
|
151
|
+
await scan.run({
|
|
152
|
+
url: 'https://localhost:8000/api/orders',
|
|
153
|
+
query: {
|
|
154
|
+
q: `<script>alert('xss')</script>`
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## License
|
|
163
|
+
|
|
164
|
+
Copyright © 2022 [Bright Security](https://brightsec.com/).
|
|
165
|
+
|
|
166
|
+
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details.
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sectester/runner",
|
|
3
|
+
"version": "0.16.1",
|
|
4
|
+
"description": "Run scanning for vulnerabilities just from your unit tests on CI phase.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/NeuraLegion/sectester-js.git"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=16",
|
|
11
|
+
"npm": "^8.1.0"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Artem Derevnjuk",
|
|
15
|
+
"email": "artem.derevnjuk@brightsec.com"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/NeuraLegion/sectester-js/issues"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"security",
|
|
26
|
+
"testing",
|
|
27
|
+
"e2e",
|
|
28
|
+
"test",
|
|
29
|
+
"typescript",
|
|
30
|
+
"appsec",
|
|
31
|
+
"pentesting",
|
|
32
|
+
"qa",
|
|
33
|
+
"brightsec"
|
|
34
|
+
],
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@sectester/bus": ">=0.16.0 <1.0.0",
|
|
37
|
+
"@sectester/core": ">=0.16.0 <1.0.0",
|
|
38
|
+
"@sectester/repeater": ">=0.16.0 <1.0.0",
|
|
39
|
+
"@sectester/reporter": ">=0.16.0 <1.0.0",
|
|
40
|
+
"@sectester/scan": ">=0.16.0 <1.0.0",
|
|
41
|
+
"reflect-metadata": "^0.1.13",
|
|
42
|
+
"uuid": "^8.3.2",
|
|
43
|
+
"tsyringe": "^4.6.0",
|
|
44
|
+
"chalk": "^4.1.2",
|
|
45
|
+
"form-data": "^4.0.0",
|
|
46
|
+
"axios": "^0.26.1",
|
|
47
|
+
"axios-rate-limit": "^1.3.0",
|
|
48
|
+
"amqp-connection-manager": "^4.1.1",
|
|
49
|
+
"amqplib": "^0.8.0",
|
|
50
|
+
"semver": "^7.3.7",
|
|
51
|
+
"socks-proxy-agent": "^6.2.0-beta.0",
|
|
52
|
+
"request-promise": "^4.2.6",
|
|
53
|
+
"request": "^2.88.2",
|
|
54
|
+
"content-type": "^1.0.4",
|
|
55
|
+
"ws": "^8.5.0",
|
|
56
|
+
"@har-sdk/core": "^1.4.3",
|
|
57
|
+
"ci-info": "^3.3.0",
|
|
58
|
+
"tty-table": "^4.1.5"
|
|
59
|
+
},
|
|
60
|
+
"main": "./src/index.js",
|
|
61
|
+
"typings": "./src/index.d.ts",
|
|
62
|
+
"dependencies": {}
|
|
63
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/runner/src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAsB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Formatter } from '@sectester/reporter';
|
|
2
|
+
import { SecTesterError } from '@sectester/core';
|
|
3
|
+
import { Issue } from '@sectester/scan';
|
|
4
|
+
export declare class IssueFound extends SecTesterError {
|
|
5
|
+
readonly issue: Issue;
|
|
6
|
+
constructor(issue: Issue, formatter: Formatter);
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IssueFound = void 0;
|
|
4
|
+
const core_1 = require("@sectester/core");
|
|
5
|
+
class IssueFound extends core_1.SecTesterError {
|
|
6
|
+
constructor(issue, formatter) {
|
|
7
|
+
super(`Target is vulnerable\n\n${formatter.format(issue)}`);
|
|
8
|
+
this.issue = issue;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.IssueFound = IssueFound;
|
|
12
|
+
//# sourceMappingURL=IssueFound.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IssueFound.js","sourceRoot":"","sources":["../../../../../packages/runner/src/lib/IssueFound.ts"],"names":[],"mappings":";;;AACA,0CAAiD;AAGjD,MAAa,UAAW,SAAQ,qBAAc;IAC5C,YAA4B,KAAY,EAAE,SAAoB;QAC5D,KAAK,CAAC,2BAA2B,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QADlC,UAAK,GAAL,KAAK,CAAO;IAExC,CAAC;CACF;AAJD,gCAIC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SecScanOptions } from './SecScanOptions';
|
|
2
|
+
import { SecScan } from './SecScan';
|
|
3
|
+
import { Configuration, ConfigurationOptions } from '@sectester/core';
|
|
4
|
+
export declare class SecRunner {
|
|
5
|
+
private readonly configuration;
|
|
6
|
+
private repeater;
|
|
7
|
+
private repeaterFactory;
|
|
8
|
+
private repeatersManager;
|
|
9
|
+
get repeaterId(): string | undefined;
|
|
10
|
+
constructor(config: Configuration | ConfigurationOptions);
|
|
11
|
+
init(): Promise<void>;
|
|
12
|
+
clear(): Promise<void>;
|
|
13
|
+
createScan(options: SecScanOptions): SecScan;
|
|
14
|
+
private initConfiguration;
|
|
15
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecRunner = void 0;
|
|
4
|
+
const SecScan_1 = require("./SecScan");
|
|
5
|
+
const core_1 = require("@sectester/core");
|
|
6
|
+
const repeater_1 = require("@sectester/repeater");
|
|
7
|
+
const scan_1 = require("@sectester/scan");
|
|
8
|
+
const reporter_1 = require("@sectester/reporter");
|
|
9
|
+
class SecRunner {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.configuration =
|
|
12
|
+
config instanceof core_1.Configuration ? config : new core_1.Configuration(config);
|
|
13
|
+
}
|
|
14
|
+
get repeaterId() {
|
|
15
|
+
var _a;
|
|
16
|
+
return (_a = this.repeater) === null || _a === void 0 ? void 0 : _a.repeaterId;
|
|
17
|
+
}
|
|
18
|
+
async init() {
|
|
19
|
+
if (this.repeatersManager && this.repeaterFactory) {
|
|
20
|
+
throw new Error('Already initialized.');
|
|
21
|
+
}
|
|
22
|
+
await this.initConfiguration(this.configuration);
|
|
23
|
+
this.repeatersManager =
|
|
24
|
+
this.configuration.container.resolve(repeater_1.RepeatersManager);
|
|
25
|
+
this.repeaterFactory =
|
|
26
|
+
this.configuration.container.resolve(repeater_1.RepeaterFactory);
|
|
27
|
+
this.repeater = await this.repeaterFactory.createRepeater();
|
|
28
|
+
await this.repeater.start();
|
|
29
|
+
}
|
|
30
|
+
async clear() {
|
|
31
|
+
try {
|
|
32
|
+
if (this.repeater && this.repeatersManager) {
|
|
33
|
+
await this.repeater.stop();
|
|
34
|
+
await this.repeatersManager.deleteRepeater(this.repeater.repeaterId);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
delete this.repeater;
|
|
39
|
+
delete this.repeatersManager;
|
|
40
|
+
delete this.repeaterFactory;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
createScan(options) {
|
|
44
|
+
if (!this.repeater) {
|
|
45
|
+
throw new Error('Must be initialized first.');
|
|
46
|
+
}
|
|
47
|
+
return new SecScan_1.SecScan({
|
|
48
|
+
...options,
|
|
49
|
+
repeaterId: this.repeater.repeaterId
|
|
50
|
+
}, this.configuration.container.resolve(scan_1.ScanFactory), this.configuration.container.resolve(reporter_1.Formatter));
|
|
51
|
+
}
|
|
52
|
+
async initConfiguration(configuration) {
|
|
53
|
+
await configuration.loadCredentials();
|
|
54
|
+
configuration.container.register(reporter_1.Formatter, {
|
|
55
|
+
useClass: reporter_1.PlainTextFormatter
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.SecRunner = SecRunner;
|
|
60
|
+
//# sourceMappingURL=SecRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecRunner.js","sourceRoot":"","sources":["../../../../../packages/runner/src/lib/SecRunner.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AACpC,0CAAsE;AACtE,kDAI6B;AAC7B,0CAA8C;AAC9C,kDAAoE;AAEpE,MAAa,SAAS;IAUpB,YAAY,MAA4C;QACtD,IAAI,CAAC,aAAa;YAChB,MAAM,YAAY,oBAAa,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,oBAAa,CAAC,MAAM,CAAC,CAAC;IACzE,CAAC;IAPD,IAAI,UAAU;;QACZ,OAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,UAAU,CAAC;IACnC,CAAC;IAOM,KAAK,CAAC,IAAI;QACf,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAC,eAAe,EAAE;YACjD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACzC;QAED,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAEjD,IAAI,CAAC,gBAAgB;YACnB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,2BAAgB,CAAC,CAAC;QACzD,IAAI,CAAC,eAAe;YAClB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,0BAAe,CAAC,CAAC;QAExD,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,cAAc,EAAE,CAAC;QAC5D,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI;YACF,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBAC1C,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC3B,MAAM,IAAI,CAAC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;aACtE;SACF;gBAAS;YACR,OAAO,IAAI,CAAC,QAAQ,CAAC;YACrB,OAAO,IAAI,CAAC,gBAAgB,CAAC;YAC7B,OAAO,IAAI,CAAC,eAAe,CAAC;SAC7B;IACH,CAAC;IAEM,UAAU,CAAC,OAAuB;QACvC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAClB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;SAC/C;QAED,OAAO,IAAI,iBAAO,CAChB;YACE,GAAG,OAAO;YACV,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU;SACrC,EACD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAc,kBAAW,CAAC,EAC9D,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAY,oBAAS,CAAC,CAC3D,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,aAA4B;QAC1D,MAAM,aAAa,CAAC,eAAe,EAAE,CAAC;QAEtC,aAAa,CAAC,SAAS,CAAC,QAAQ,CAAC,oBAAS,EAAE;YAC1C,QAAQ,EAAE,6BAAkB;SAC7B,CAAC,CAAC;IACL,CAAC;CACF;AAlED,8BAkEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Formatter } from '@sectester/reporter';
|
|
2
|
+
import { ScanFactory, ScanSettingsOptions, Severity, TargetOptions } from '@sectester/scan';
|
|
3
|
+
export declare class SecScan {
|
|
4
|
+
private readonly settings;
|
|
5
|
+
private readonly scanFactory;
|
|
6
|
+
private readonly formatter;
|
|
7
|
+
private _threshold;
|
|
8
|
+
private _timeout;
|
|
9
|
+
constructor(settings: Omit<ScanSettingsOptions, 'target'>, scanFactory: ScanFactory, formatter: Formatter);
|
|
10
|
+
run(target: TargetOptions): Promise<void>;
|
|
11
|
+
threshold(severity: Severity): SecScan;
|
|
12
|
+
timeout(value: number): SecScan;
|
|
13
|
+
private assert;
|
|
14
|
+
private findExpectedIssue;
|
|
15
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecScan = void 0;
|
|
4
|
+
const IssueFound_1 = require("./IssueFound");
|
|
5
|
+
const scan_1 = require("@sectester/scan");
|
|
6
|
+
class SecScan {
|
|
7
|
+
constructor(settings, scanFactory, formatter) {
|
|
8
|
+
this.settings = settings;
|
|
9
|
+
this.scanFactory = scanFactory;
|
|
10
|
+
this.formatter = formatter;
|
|
11
|
+
this._threshold = scan_1.Severity.LOW;
|
|
12
|
+
}
|
|
13
|
+
async run(target) {
|
|
14
|
+
const scan = await this.scanFactory.createScan({
|
|
15
|
+
...this.settings,
|
|
16
|
+
target
|
|
17
|
+
}, {
|
|
18
|
+
timeout: this._timeout
|
|
19
|
+
});
|
|
20
|
+
try {
|
|
21
|
+
await scan.expect(this._threshold);
|
|
22
|
+
await this.assert(scan);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await scan.stop();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
threshold(severity) {
|
|
29
|
+
this._threshold = severity;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
timeout(value) {
|
|
33
|
+
this._timeout = value;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
async assert(scan) {
|
|
37
|
+
const issue = await this.findExpectedIssue(scan);
|
|
38
|
+
if (issue) {
|
|
39
|
+
throw new IssueFound_1.IssueFound(issue, this.formatter);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async findExpectedIssue(scan) {
|
|
43
|
+
const issues = await scan.issues();
|
|
44
|
+
if (this._threshold) {
|
|
45
|
+
return issues.find(x => { var _a; return (_a = scan_1.severityRanges.get(this._threshold)) === null || _a === void 0 ? void 0 : _a.includes(x.severity); });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.SecScan = SecScan;
|
|
50
|
+
//# sourceMappingURL=SecScan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecScan.js","sourceRoot":"","sources":["../../../../../packages/runner/src/lib/SecScan.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,0CAQyB;AAEzB,MAAa,OAAO;IAIlB,YACmB,QAA6C,EAC7C,WAAwB,EACxB,SAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAqC;QAC7C,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;QAN/B,eAAU,GAAG,eAAQ,CAAC,GAAG,CAAC;IAO/B,CAAC;IAEG,KAAK,CAAC,GAAG,CAAC,MAAqB;QACpC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,UAAU,CAC5C;YACE,GAAG,IAAI,CAAC,QAAQ;YAChB,MAAM;SACP,EACD;YACE,OAAO,EAAE,IAAI,CAAC,QAAQ;SACvB,CACF,CAAC;QAEF,IAAI;YACF,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAEnC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACzB;gBAAS;YACR,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;SACnB;IACH,CAAC;IAEM,SAAS,CAAC,QAAkB;QACjC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,OAAO,CAAC,KAAa;QAC1B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QAEtB,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,IAAU;QAC7B,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEjD,IAAI,KAAK,EAAE;YACT,MAAM,IAAI,uBAAU,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;SAC7C;IACH,CAAC;IAEO,KAAK,CAAC,iBAAiB,CAAC,IAAU;QACxC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QAEnC,IAAI,IAAI,CAAC,UAAU,EAAE;YACnB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WACrB,OAAA,MAAA,qBAAc,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,0CAAE,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA,EAAA,CAC1D,CAAC;SACH;IACH,CAAC;CACF;AA3DD,0BA2DC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SecScanOptions.js","sourceRoot":"","sources":["../../../../../packages/runner/src/lib/SecScanOptions.ts"],"names":[],"mappings":""}
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecScan = exports.SecRunner = void 0;
|
|
4
|
+
var SecRunner_1 = require("./SecRunner");
|
|
5
|
+
Object.defineProperty(exports, "SecRunner", { enumerable: true, get: function () { return SecRunner_1.SecRunner; } });
|
|
6
|
+
var SecScan_1 = require("./SecScan");
|
|
7
|
+
Object.defineProperty(exports, "SecScan", { enumerable: true, get: function () { return SecScan_1.SecScan; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/runner/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|