This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from quantum-sec/feature/VAPT-87
VAPT-87: Add support for Zed Attack Proxy full scan
- Loading branch information
Showing
10 changed files
with
229 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ZapCollector } from './zap-collector'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import { Logger } from '../utils'; | ||
import { createLoggerFixture } from '../test/logger.fixture'; | ||
import { ZapCollector } from './zap-collector'; | ||
import { CheckResult } from '../check-result'; | ||
|
||
describe('ZapCollector', () => { | ||
|
||
let collector: ZapCollector; | ||
let logger: Logger; | ||
|
||
beforeEach(() => { | ||
logger = createLoggerFixture(); | ||
collector = new ZapCollector(logger); | ||
|
||
spyOn(collector, 'spawn').and.returnValue(new Promise((resolve) => { | ||
resolve('TEST_OUTPUT'); | ||
})); | ||
}); | ||
|
||
describe('constructor()', () => { | ||
it('should set the tool ID', () => { | ||
expect(collector.toolId).toEqual('zap'); | ||
}); | ||
}); | ||
|
||
describe('getToolVersion()', () => { | ||
it('should call zap with the -version flag', async () => { | ||
const result = await collector.getToolVersion({}); | ||
expect(result).toEqual('TEST_OUTPUT'); | ||
expect(collector.spawn).toHaveBeenCalledTimes(1); | ||
expect(collector.spawn).toHaveBeenCalledWith('zap.sh', | ||
['-cmd -version'], | ||
{}); | ||
}); | ||
}); | ||
|
||
describe('getResults()', () => { | ||
it('should call zap with preset options', async () => { | ||
collector._argv = { | ||
'target-name': 'TEST_TARGET', | ||
} as any; | ||
spyOn(collector.fs, 'readFileSync').and.returnValue('TEST_OUTPUT'); | ||
spyOn(collector, 'parseResults').and.returnValue('TEST_RESULTS' as any); | ||
const result = await collector.getResults({}); | ||
expect(result).toEqual('TEST_RESULTS' as any); | ||
|
||
const expectedArgs = [ | ||
'-t', | ||
'TEST_TARGET', | ||
'-J zapreport.json', | ||
'-s', | ||
]; | ||
expect(collector.spawn).toHaveBeenCalledTimes(1); | ||
expect(collector.spawn).toHaveBeenCalledWith('zap-full-scan.py', expectedArgs, {}); | ||
|
||
expect(collector.parseResults).toHaveBeenCalledTimes(1); | ||
expect(collector.parseResults).toHaveBeenCalledWith('TEST_OUTPUT'); | ||
}); | ||
it('should error when target name is not specified', async () => { | ||
await expectAsync(collector.getResults({})) | ||
.toBeRejectedWith(new Error('You must specify an --target-name argument.')); | ||
}); | ||
|
||
}); | ||
|
||
describe('parseResults()', () => { | ||
|
||
let raw: string; | ||
|
||
beforeEach(()=> { | ||
raw = JSON.stringify([{ | ||
alerts: [{ | ||
pluginid: 'TEST_PLUGIN_ID', | ||
alert: 'TEST_ALERT', | ||
instances: { | ||
uri: 'TEST_URI', | ||
method: 'TEST_METHOD', | ||
}, | ||
}], | ||
}]); | ||
}); | ||
|
||
it('should report passing when the result contains no vulnerabilities', () => { | ||
raw = JSON.stringify([{}]); | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.checkResult).toEqual(CheckResult.PASS); | ||
}); | ||
|
||
it('should report failing when no vulnerabilities were found', () => { | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.checkResult).toEqual(CheckResult.FAIL); | ||
}); | ||
|
||
it('should set the checkId to pluginid', () => { | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.checkId).toEqual('TEST_PLUGIN_ID'); | ||
}); | ||
|
||
it('should set the checkName to the alert name', () => { | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.checkName).toEqual('TEST_ALERT'); | ||
}); | ||
|
||
it('should set the resourceId to instances.uri', () => { | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.resourceId).toEqual('TEST_URI'); | ||
}); | ||
|
||
it('should set the checkMethod to instances.method', () => { | ||
const result = collector.parseResults(raw)[0]; | ||
expect(result.checkMethod).toEqual('TEST_METHOD'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { AnalysisCollectorBase } from '../analysis-collector-base'; | ||
import { CheckResult } from '../check-result'; | ||
import { IResult } from '../result.interface'; | ||
import { Logger } from '../utils'; | ||
import * as fs from 'fs'; | ||
|
||
export class ZapCollector extends AnalysisCollectorBase { | ||
public fs = fs; | ||
|
||
public constructor(logger: Logger) { | ||
super('zap', logger); | ||
} | ||
|
||
public override async getToolVersion(options: any): Promise<string> { | ||
const args = ['-cmd -version']; | ||
return await this.spawn('zap.sh', args, options); | ||
} | ||
|
||
public override async getResults(options: any): Promise<IResult[]> { | ||
const targetName = this._argv['target-name']; | ||
if (!targetName) { | ||
throw new Error('You must specify an --target-name argument.'); | ||
} | ||
|
||
const args = ['-t', targetName, '-J zapreport.json', '-s']; | ||
const output = await this.spawn('zap-full-scan.py', args, options); | ||
|
||
|
||
const jsonFileContents: string = this.fs.readFileSync('zapreport.json', 'utf8'); | ||
this.logger.debug(JSON.stringify(output, null, 2)); | ||
|
||
return this.parseResults(jsonFileContents); | ||
} | ||
|
||
public parseResults(output: string): IResult[] { | ||
const parsed = JSON.parse(output); | ||
|
||
const results = []; | ||
|
||
for (const set of parsed) { | ||
if (!set.alerts) { | ||
const result: IResult = { | ||
checkId: 'vulnerabilities', | ||
checkName: 'No vulnerabilities found.', | ||
checkType: 'website', | ||
checkResult: CheckResult.PASS, | ||
resourceId: set.name, | ||
}; | ||
|
||
results.push(result); | ||
continue; | ||
} | ||
|
||
results.push(...set.alerts.map((v) => { | ||
const result: IResult = { | ||
checkId: v.pluginid, | ||
checkName: v.alert, | ||
checkType: 'website', | ||
checkResult: CheckResult.FAIL, | ||
resourceId: v.instances.uri, | ||
checkMethod: v.instances.method, | ||
}; | ||
|
||
return result; | ||
})); | ||
|
||
} | ||
return results; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters