Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF-174: Artifact #97

Merged
merged 5 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/attack_flow_builder/src/assets/builder.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,19 @@ const config: AppConfiguration = {
payload_bin : { type: PropertyType.String },
url : { type: PropertyType.String },
hashes : { type: PropertyType.String },
encryption_algorithm : { type: PropertyType.String },
encryption_algorithm : {
type: PropertyType.Enum,
options: {
type: PropertyType.List,
form: { type: PropertyType.String },
value: [
["AES-256-GCM", "AES-256-GCM"],
["ChaCha20-Poly1305", "ChaCha20-Poly1305"],
["mime-type-indicated", "Mime Type Indicated"],
]
},
value: null
},
decryption_key : { type: PropertyType.String },
},
anchor_template: "@__builtin__anchor",
Expand Down
51 changes: 51 additions & 0 deletions src/attack_flow_builder/src/assets/builder.config.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,57 @@ class AttackFlowValidator extends DiagramValidator {
}
// Validate links
switch(node.template.id) {
case "artifact":
const payloadBin = node.props.value.get("payload_bin");
const url = node.props.value.get("url");
const hashes = node.props.value.get("hashes");
const mimeType = node.props.value.get("mime_type");
const decryptionKey = node.props.value.get("decryption_key");
const encryptionAlg = node.props.value.get("encryption_algorithm")

const payloadRegex = /^([a-z0-9+/]{4})*([a-z0-9+/]{4}|[a-z0-9+/]{3}=|[a-z0-9+/]{2}==)$/i;
const MIME_Regex = /^(application|audio|font|image|message|model|multipart|text|video)\/[a-zA-Z0-9.+_-]+/;

// Check regex
if(payloadBin?.isDefined()) {
if(!payloadRegex.test(payloadBin.toString())) {
this.addError(id, "Invalid Payload Bin.");
}
}
if(mimeType?.isDefined()) {
if(!MIME_Regex.test(mimeType.toString())) {
this.addError(id, "Invalid MIME Type.");
}
}

if(!payloadBin?.isDefined() && !url?.isDefined() && !hashes?.isDefined() && !encryptionAlg?.isDefined() && !decryptionKey?.isDefined()) { // A blank object
mikecarenzo marked this conversation as resolved.
Show resolved Hide resolved
this.addError(id, "Artifact must have one of following combinations of fields filled out: (Payload Bin), or (URL + Hashes - Payload Bin)");
} else {
if(payloadBin?.isDefined()) {
if(url?.isDefined()) {
// Invalid combination
this.addError(id, "Artifact must have one of following combinations of fields filled out: (Payload Bin), or (URL + Hashes - Payload Bin)");
}
} else {
if(encryptionAlg?.isDefined()) {
mikecarenzo marked this conversation as resolved.
Show resolved Hide resolved
// Valid
if(encryptionAlg.toRawValue()?.toString() == "mime-type-indicated" && !mimeType?.isDefined()) {
this.addError(id, "For Encryption Algorithm to be 'Mime Type Indicated', the field 'Mime Type' cannot be empty.");
}
} else {
if(decryptionKey?.isDefined()) {
this.addError(id, "An Artifact with a Decryption Key must also have an Encryption Algorithm.");
}
}

if(url?.isDefined() && hashes?.isDefined()) {
// Valid
} else {
this.addError(id, "Artifact must have one of following combinations of fields filled out: (Payload Bin), or (URL + Hashes - Payload Bin)");
}
}
}
break;
case "email_address": // Additional validation for email addresses
if (!AttackFlowValidator.Emailregex.test(String(node.props.value.get("value")))) {
this.addError(id, "Invalid email address.")
Expand Down
Loading