fase(6): fuzzing module complete
This commit is contained in:
96
dist/modules/fuzzing/domain/entities/FuzzSession.js
vendored
Normal file
96
dist/modules/fuzzing/domain/entities/FuzzSession.js
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.FuzzSession = void 0;
|
||||
const AggregateRoot_1 = require("../../../../shared/domain/AggregateRoot");
|
||||
const Result_1 = require("../../../../shared/domain/Result");
|
||||
const FuzzIntensity_1 = require("../value-objects/FuzzIntensity");
|
||||
const Seed_1 = require("../value-objects/Seed");
|
||||
const FuzzStarted_1 = require("../events/FuzzStarted");
|
||||
const FuzzCompleted_1 = require("../events/FuzzCompleted");
|
||||
const VulnerabilityDetected_1 = require("../events/VulnerabilityDetected");
|
||||
class FuzzSession extends AggregateRoot_1.AggregateRoot {
|
||||
constructor(props, id) {
|
||||
super(props, id);
|
||||
}
|
||||
static reconstitute(props, id) {
|
||||
return new FuzzSession(props, id);
|
||||
}
|
||||
static create(request) {
|
||||
let intensity;
|
||||
try {
|
||||
intensity = FuzzIntensity_1.FuzzIntensity.fromString(request.intensity);
|
||||
}
|
||||
catch (e) {
|
||||
return (0, Result_1.Err)(e.message);
|
||||
}
|
||||
let seed;
|
||||
try {
|
||||
seed = Seed_1.Seed.create(request.seed);
|
||||
}
|
||||
catch (e) {
|
||||
return (0, Result_1.Err)(e.message);
|
||||
}
|
||||
const props = {
|
||||
crawlSessionId: request.crawlSessionId,
|
||||
intensity,
|
||||
seed,
|
||||
status: 'running',
|
||||
actionsExecuted: 0,
|
||||
vulnerabilitiesFound: 0,
|
||||
startedAt: new Date(),
|
||||
};
|
||||
const session = new FuzzSession(props);
|
||||
session.addDomainEvent(new FuzzStarted_1.FuzzStarted(session.id.toString(), {
|
||||
crawlSessionId: request.crawlSessionId,
|
||||
intensity: request.intensity,
|
||||
seed: request.seed,
|
||||
}));
|
||||
return (0, Result_1.Ok)(session);
|
||||
}
|
||||
get crawlSessionId() { return this.props.crawlSessionId; }
|
||||
get intensity() { return this.props.intensity; }
|
||||
get seed() { return this.props.seed; }
|
||||
get status() { return this.props.status; }
|
||||
get actionsExecuted() { return this.props.actionsExecuted; }
|
||||
get vulnerabilitiesFound() { return this.props.vulnerabilitiesFound; }
|
||||
get startedAt() { return this.props.startedAt; }
|
||||
get completedAt() { return this.props.completedAt; }
|
||||
recordVulnerability(result) {
|
||||
this.props = {
|
||||
...this.props,
|
||||
actionsExecuted: this.props.actionsExecuted + 1,
|
||||
vulnerabilitiesFound: this.props.vulnerabilitiesFound + 1,
|
||||
};
|
||||
this.addDomainEvent(new VulnerabilityDetected_1.VulnerabilityDetected(this.id.toString(), {
|
||||
crawlSessionId: this.props.crawlSessionId,
|
||||
stateId: result.stateId,
|
||||
anomalyType: result.anomalyType,
|
||||
severity: result.severity,
|
||||
selector: result.selector,
|
||||
payload: result.payload,
|
||||
strategy: result.strategy,
|
||||
}));
|
||||
}
|
||||
incrementActions() {
|
||||
this.props = { ...this.props, actionsExecuted: this.props.actionsExecuted + 1 };
|
||||
}
|
||||
complete() {
|
||||
this.props = { ...this.props, status: 'completed', completedAt: new Date() };
|
||||
this.addDomainEvent(new FuzzCompleted_1.FuzzCompleted(this.id.toString(), {
|
||||
crawlSessionId: this.props.crawlSessionId,
|
||||
actionsExecuted: this.props.actionsExecuted,
|
||||
vulnerabilitiesFound: this.props.vulnerabilitiesFound,
|
||||
}));
|
||||
}
|
||||
fail(reason) {
|
||||
this.props = { ...this.props, status: 'failed', completedAt: new Date() };
|
||||
this.addDomainEvent(new FuzzCompleted_1.FuzzCompleted(this.id.toString(), {
|
||||
crawlSessionId: this.props.crawlSessionId,
|
||||
actionsExecuted: this.props.actionsExecuted,
|
||||
vulnerabilitiesFound: this.props.vulnerabilitiesFound,
|
||||
failed: true,
|
||||
reason,
|
||||
}));
|
||||
}
|
||||
}
|
||||
exports.FuzzSession = FuzzSession;
|
||||
Reference in New Issue
Block a user