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

Test for MAGIC in server response #14

Merged
merged 4 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ typings/
# next.js build output
.next

.vscode/*
.vscode/*
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ A Docker image can be built, then run by doing the following:
## API overview
> For full documentation of the API, you can find the swagger page hosted at the root url. See [Installing](#Installing) to run the application and browse the docs.

Currently the server just has one endpoint: `/bake`. This endpoint accepts a POST request with the following body:
The server has two endpoints: `/bake` and `/magic`.

### `/bake`

`/bake` allows a user to POST some input and configuration for a CyberChef Recipe. The application will run the input through the recipe and return the baked operation.

This endpoint accepts a POST request with the following body:

|Parameter|Type|Description|
|---|---|---|
Expand Down Expand Up @@ -160,6 +166,53 @@ Response:
}
```

### `/magic`

[Find more information about what the Magic operation does here](https://github.com/gchq/CyberChef/wiki/Automatic-detection-of-encoded-data-using-CyberChef-Magic)

The Magic operation cannot be used in conjunction with other applications in the `/bake` endpoint.


|Parameter|Type|Description|
|---|---|---|
input|String|The input data for the recipe. Currently accepts strings.
args|Object or Array|Arguments for the magic operation

#### Example: detecting hex
```javascript
{
"input": "4f 6e 65 2c 20 74 77 6f 2c 20 74 68 72 65 65 2c 20 66 6f 75 72 2e"
}
```
Response:
```javascript
{
"value": [
{
"recipe": [
{ "op": "From Hex", "args": [ "Space" ] }
],
"data": "One, two, three, four.",
"languageScores": [
{ "lang": "en", "score": 442.77940826119266, "probability": 2.8158586573567845e-12 },
{ "lang": "de", "score": 555.3142876037181, "probability": 0 },
{ "lang": "pl", "score": 560.9378201619123, "probability": 0 },
...
],
"fileType": null,
"isUTF8": true,
"entropy": 3.5383105956150076,
"matchingOps": [],
"useful": false,
"matchesCrib": null
},
...
],
"type":6
}
```


## Licencing

CyberChef-server is released under the [Apache 2.0 Licence](https://www.apache.org/licenses/LICENSE-2.0) and is covered by [Crown Copyright](https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/copyright-and-re-use/crown-copyright/).
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import errorHandler from "./lib/errorHandler.js";
import helmet from "helmet";

import bakeRouter from "./routes/bake";
import magicRouter from "./routes/magic";

const app = express();
app.disable("x-powered-by");
Expand Down Expand Up @@ -37,6 +38,7 @@ const swaggerFile = fs.readFileSync("./swagger.yml", "utf8");

// Routes
app.use("/bake", bakeRouter);
app.use("/magic", magicRouter);


// Default route
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions routes/magic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Router } from "express";
const router = Router();
import { magic } from "cyberchef/src/node/index.mjs";

/**
* magicPost
*/
router.post("/", async function magicPost(req, res, next) {
try {
if (!req.body.input) {
throw new TypeError("'input' property is required in request body");
}

const dish = await magic(req.body.input, req.body.args);
res.send(dish);

} catch (e) {
next(e);
}
});

export default router;
94 changes: 92 additions & 2 deletions swagger.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: CyberChef API
description: Some API
description: A HTTP API that exposes some of CyberChef's functionality.
version: 1.0.0


Expand Down Expand Up @@ -41,10 +41,64 @@ paths:
application/json:
schema:
type: "string"
example: "62 61 6b 65 20 73 6f 6d 65 74 68 69 6e 67"
value: "Object"
example:
type: "string"
value: "01001110,01111010,01001101,01100111,01001110,01101101,01011001,01100111,01001110,01101101,01010001,01100111,01001110,01101010,01010101,01100111,01001101,01101010,01000001,01100111,01001110,01101010,01101011,01100111,01001110,01101101,01010101,01100111,01001110,01111010,01000001,01100111,01001110,01111010,01010101,01100111,01001110,01111010,01010001,00111101"
'400':
description: Bad request

/magic:
post:
summary: Performs magic on some input
description: >
Take some input data and optional arguments for the [Magic operation](https://github.com/gchq/CyberChef/wiki/Automatic-detection-of-encoded-data-using-CyberChef-Magic) and return JSON of results of automatic encoding detection of the inputted data.

requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/MagicInput"
example:
input: "WUagwsiae6mP8gNtCCLUFpCpCB26RmBDoDD8PacdAmzAzBVjkK2QstFXaKhpC6iUS7RHqXrJtFisoRSgoJ4whjm1arm864qaNq4RcfUmLHrcsAaZc5TXCYifNdgS83gDeejGX46gaiMyuBV6EskHt1scgJ88x2tNSotQDwbGY1mmCob2ARGFvCKYNqiN9ipMq1ZU1mgkdbNuGcb76aRtYWhCGUc8g93UJudhb8htsheZnwTpgqhx83SVJSZXMXUjJT2zmpC7uXWtumqokbdSi88YtkWDAc1Toouh2oH4D4ddmNKJWUDpMwmngUmK14xwmomccPQE9hM172APnSqwxdKQ172RkcAsysnmj5gGtRmVNNh2s359wr6mS2QRP"
args:
depth: 1

responses:
'200':
description: Magic operation ran successfully
content:
application/json:
schema:
type: "string"
value:
$ref: "#/components/schemas/MagicResponse"
example:
type: 6
value:
- recipe:
- op: "From Base58"
args:
- "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
- false
data: "x^Ü^Í^ÒÑqÃ0\fCWá\b^ÉcKò8mâì?B\u001eA^ÊUûÕ»^ÜOb@\u0010^ÀxìÖ^Ƶö^Ûµ§µ»õ^Çõ]×ÃzÓwÓ\u0015äÛ1^Ý3-§µKõ^×0t=¼½õdë\u001cÄ^Ö^ØS\u0000uÁ\u001f´Pñõ³*^ÌppuÝÅ\u0003"
languageScores:
- lang: zh
score: 215110.97112616687
probability: 0
fileType: null
isUTF8: true
entropy: 5.6887987925007035
matchingOps:
- op: "From Base58"
pattern: {}
args:
- 123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
- false
useful: false


components:
schemas:
SingleOpRecipe:
Expand Down Expand Up @@ -99,4 +153,40 @@ components:
width: 16
upperCaseHex: true
includeFinalLength: false

MagicInput:
type: object
properties:
input: {}
args:
oneOf:
- $ref: "#/components/schemas/ArgArray"
- $ref: "#/components/schemas/ArgObject"
MagicResponse:
type: object
properties:
type:
type: int
value:
type: array
items:
$ref: "#/components/schemas/MagicResponseItem"
MagicResponseItem:
type: object
properties:
recipe:
type: array
items:
type: Object
data:
type: string
languageScores:
type: array
items:
type: Object
matchingOps:
type: array
items:
type: Object
useful: bool

Loading