mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-14 01:56:54 -04:00
mime-checking added to magic now
This commit is contained in:
parent
0a4fae1576
commit
ee37731858
5 changed files with 37 additions and 3 deletions
|
@ -53,6 +53,10 @@ for (const opObj in Ops) {
|
||||||
if ("inRegexes" in op.checks) {
|
if ("inRegexes" in op.checks) {
|
||||||
operationConfig[op.name].inputRegexes = op.checks.inRegexes;
|
operationConfig[op.name].inputRegexes = op.checks.inRegexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("mimeCheck" in op.checks) {
|
||||||
|
operationConfig[op.name].mimeCheck = op.checks.mimeCheck;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(op.module in modules))
|
if (!(op.module in modules))
|
||||||
|
|
|
@ -5,6 +5,7 @@ import Dish from "../Dish.mjs";
|
||||||
import {detectFileType} from "./FileType.mjs";
|
import {detectFileType} from "./FileType.mjs";
|
||||||
import chiSquared from "chi-squared";
|
import chiSquared from "chi-squared";
|
||||||
import potentialOps from "./Test.mjs";
|
import potentialOps from "./Test.mjs";
|
||||||
|
import { isImage } from "./FileType.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class for detecting encodings, file types and byte frequencies and
|
* A class for detecting encodings, file types and byte frequencies and
|
||||||
|
@ -244,6 +245,23 @@ class Magic {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks the mime value of the data compared to the specified type.
|
||||||
|
*
|
||||||
|
* @param {ArrayBuffer} data
|
||||||
|
* @param {string} type
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
async checkMime (data, type) {
|
||||||
|
switch (type) {
|
||||||
|
case "Image":
|
||||||
|
if (isImage(data))
|
||||||
|
return false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the checks to validate the input/output of potential operations.
|
* Uses the checks to validate the input/output of potential operations.
|
||||||
*
|
*
|
||||||
|
@ -276,6 +294,11 @@ class Magic {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mime = OperationConfig[op.op].mimeCheck;
|
||||||
|
if (mime)
|
||||||
|
if (await this.checkMime(output, mime.type))
|
||||||
|
return;
|
||||||
|
|
||||||
// If the recipe returned an empty buffer, do not continue
|
// If the recipe returned an empty buffer, do not continue
|
||||||
if (_buffersEqual(output, new ArrayBuffer())) {
|
if (_buffersEqual(output, new ArrayBuffer())) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,10 +5,12 @@ class magicObject {
|
||||||
/**
|
/**
|
||||||
* @param inRegexes
|
* @param inRegexes
|
||||||
* @param outRegexes
|
* @param outRegexes
|
||||||
|
* @param mimeCheck
|
||||||
*/
|
*/
|
||||||
constructor (inRegexes = null, outRegexes = null) {
|
constructor (inRegexes = null, outRegexes = null, mimeCheck = null) {
|
||||||
this.inRegexes = inRegexes;
|
this.inRegexes = inRegexes;
|
||||||
this.outRegexes = outRegexes;
|
this.outRegexes = outRegexes;
|
||||||
|
this.mimeCheck = mimeCheck;
|
||||||
}
|
}
|
||||||
|
|
||||||
} export default magicObject;
|
} export default magicObject;
|
||||||
|
|
|
@ -28,7 +28,7 @@ class ObjectIdentifierToHex extends Operation {
|
||||||
this.args = [];
|
this.args = [];
|
||||||
this.checks = new magicObject([
|
this.checks = new magicObject([
|
||||||
{
|
{
|
||||||
match: "^\\s*([0-9]{1,3}\\.?)+\\s*$",
|
match: "^\\s*([0-9]{1,3}\\.)+[0-9]{1,3}\\s*$",
|
||||||
flags: "",
|
flags: "",
|
||||||
magic: true,
|
magic: true,
|
||||||
args: []
|
args: []
|
||||||
|
|
|
@ -44,7 +44,12 @@ class RenderImage extends Operation {
|
||||||
args: ["Raw"],
|
args: ["Raw"],
|
||||||
useful: true
|
useful: true
|
||||||
}
|
}
|
||||||
]);
|
],
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
type: "Image",
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue