oculon 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -13
- package/dist/cli/main.js +316 -1
- package/dist/core/der.d.ts +2 -0
- package/dist/core/der.js +17 -0
- package/dist/core/http.d.ts +19 -1
- package/dist/core/http.js +24 -0
- package/dist/core/qr.d.ts +23 -0
- package/dist/core/qr.js +577 -0
- package/dist/core/quota.js +5 -0
- package/dist/core/raster.d.ts +6 -0
- package/dist/core/raster.js +298 -0
- package/dist/core/safeurl.d.ts +5 -0
- package/dist/core/safeurl.js +26 -0
- package/dist/core/verdict.js +1 -1
- package/dist/core/zip.d.ts +9 -0
- package/dist/core/zip.js +46 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +99 -0
- package/dist/mcp.js +131 -5
- package/dist/modules/address.d.ts +6 -2
- package/dist/modules/address.js +32 -5
- package/dist/modules/apk.d.ts +37 -0
- package/dist/modules/apk.js +191 -0
- package/dist/modules/approvals.d.ts +40 -0
- package/dist/modules/approvals.js +155 -0
- package/dist/modules/archive.d.ts +21 -0
- package/dist/modules/archive.js +94 -0
- package/dist/modules/checks.js +33 -0
- package/dist/modules/contract.d.ts +56 -0
- package/dist/modules/contract.js +167 -0
- package/dist/modules/deployer.d.ts +42 -0
- package/dist/modules/deployer.js +90 -0
- package/dist/modules/doc.d.ts +24 -2
- package/dist/modules/doc.js +133 -7
- package/dist/modules/eml.d.ts +46 -0
- package/dist/modules/eml.js +175 -0
- package/dist/modules/hashcheck.d.ts +19 -3
- package/dist/modules/hashcheck.js +28 -4
- package/dist/modules/image.d.ts +32 -0
- package/dist/modules/image.js +276 -0
- package/dist/modules/invite.d.ts +27 -0
- package/dist/modules/invite.js +69 -0
- package/dist/modules/job.d.ts +33 -0
- package/dist/modules/job.js +64 -0
- package/dist/modules/meerkat.d.ts +1 -1
- package/dist/modules/meerkat.js +35 -2
- package/dist/modules/monitor.js +14 -0
- package/dist/modules/poisoning.d.ts +43 -0
- package/dist/modules/poisoning.js +114 -0
- package/dist/modules/qrcheck.d.ts +24 -0
- package/dist/modules/qrcheck.js +136 -0
- package/dist/modules/repo.d.ts +61 -0
- package/dist/modules/repo.js +162 -0
- package/dist/modules/report.d.ts +32 -0
- package/dist/modules/report.js +108 -0
- package/dist/modules/signature.d.ts +35 -0
- package/dist/modules/signature.js +283 -0
- package/dist/modules/site.d.ts +62 -0
- package/dist/modules/site.js +191 -0
- package/dist/modules/stocktoken.d.ts +48 -0
- package/dist/modules/stocktoken.js +99 -0
- package/dist/modules/trace.d.ts +37 -0
- package/dist/modules/trace.js +150 -0
- package/dist/modules/txexplain.d.ts +40 -0
- package/dist/modules/txexplain.js +135 -0
- package/dist/modules/urlcheck.js +15 -1
- package/dist/modules/where.d.ts +63 -0
- package/dist/modules/where.js +165 -0
- package/dist/report-pdf.js +3 -0
- package/dist/sources/cfurlscan.d.ts +24 -0
- package/dist/sources/cfurlscan.js +46 -0
- package/dist/sources/chainabuse.d.ts +17 -0
- package/dist/sources/chainabuse.js +19 -0
- package/dist/sources/evm.d.ts +135 -0
- package/dist/sources/evm.js +260 -0
- package/dist/sources/phishlists.d.ts +20 -0
- package/dist/sources/phishlists.js +90 -0
- package/dist/telegram.d.ts +17 -0
- package/dist/telegram.js +151 -4
- package/dist/web/docs.html +1 -1
- package/dist/web/index.html +147 -11
- package/dist/web/landing.html +1 -1
- package/dist/web/legal.html +3 -1
- package/dist/web/mcp.html +1 -1
- package/dist/web/openapi.js +13 -0
- package/dist/web/pages.js +2 -2
- package/dist/web/public.js +14 -1
- package/dist/web/server.d.ts +13 -0
- package/dist/web/server.js +77 -12
- package/dist/web/token.html +24 -4
- package/dist/web/token.json +12 -1
- package/package.json +2 -2
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { signalId } from '../core/text.js';
|
|
2
|
+
import { esTxList, etherscan, evmChain, isAddr, labelOf, tokenMeta } from '../sources/evm.js';
|
|
3
|
+
import { DEX_CHAIN } from '../sources/onchain.js';
|
|
4
|
+
import { describeLabels, ensureLabels, labelsFor } from '../sources/labels.js';
|
|
5
|
+
export async function deployerCheck(ctx, input, opts = {}) {
|
|
6
|
+
const token = input.trim().toLowerCase();
|
|
7
|
+
if (!isAddr(token))
|
|
8
|
+
throw new Error('give a token contract address: 0x followed by 40 hex characters');
|
|
9
|
+
const c = evmChain(opts.chain, 'creation');
|
|
10
|
+
const provenance = [];
|
|
11
|
+
const cr = await etherscan(ctx, c, { module: 'contract', action: 'getcontractcreation', contractaddresses: token }, 86_400);
|
|
12
|
+
provenance.push(cr.prov);
|
|
13
|
+
const row = cr.data?.[0];
|
|
14
|
+
const now = ctx.now();
|
|
15
|
+
const base = { token, chain: c.label };
|
|
16
|
+
if (!row?.contractCreator) {
|
|
17
|
+
return { module: 'deployer', input: token, generatedAt: now.toISOString(), signals: [], provenance, result: { ...base, deployer: null, createdAt: null, verdict: 'deployer not found', risk: 0, deployments: [], tokens: 0, dead: 0, fundedBy: null, reasons: [], notes: ['Etherscan has no creator for this address: it may not be a contract on this chain.'], advice: [] } };
|
|
18
|
+
}
|
|
19
|
+
const deployer = row.contractCreator.toLowerCase();
|
|
20
|
+
const createdAt = row.timestamp ? new Date(Number(row.timestamp) * 1000).toISOString() : null;
|
|
21
|
+
const txs = await esTxList(ctx, c, deployer, 1000, 'asc');
|
|
22
|
+
provenance.push(txs.prov);
|
|
23
|
+
const list = txs.data ?? [];
|
|
24
|
+
const created = list.filter((t) => !t.to && t.contractAddress && t.from.toLowerCase() === deployer).map((t) => ({ address: t.contractAddress.toLowerCase(), at: new Date(Number(t.timeStamp) * 1000).toISOString() }));
|
|
25
|
+
if (!created.some((x) => x.address === token))
|
|
26
|
+
created.push({ address: token, at: createdAt ?? now.toISOString() });
|
|
27
|
+
const recent = created.slice(-30);
|
|
28
|
+
// Pools today, 30 tokens per DexScreener call.
|
|
29
|
+
const liq = new Map();
|
|
30
|
+
for (let i = 0; i < recent.length; i += 30) {
|
|
31
|
+
const r = await ctx.http.get(`https://api.dexscreener.com/tokens/v1/${DEX_CHAIN[c.key] ?? c.key}/${recent.slice(i, i + 30).map((x) => x.address).join(',')}`, { source: 'dexscreener', ttlSec: 900 });
|
|
32
|
+
if (i === 0)
|
|
33
|
+
provenance.push(r.prov);
|
|
34
|
+
for (const p of Array.isArray(r.data) ? r.data : []) {
|
|
35
|
+
const a = p.baseToken?.address?.toLowerCase();
|
|
36
|
+
if (a)
|
|
37
|
+
liq.set(a, Math.max(liq.get(a) ?? 0, p.liquidity?.usd ?? 0));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const deployments = [];
|
|
41
|
+
for (const d of recent) {
|
|
42
|
+
const m = await tokenMeta(ctx, c, d.address);
|
|
43
|
+
const isToken = Boolean(m.symbol && m.decimals !== null);
|
|
44
|
+
const l = liq.has(d.address) ? liq.get(d.address) : null;
|
|
45
|
+
deployments.push({ address: d.address, symbol: m.symbol, name: m.name, createdAt: d.at, liquidityUsd: l, dead: isToken && (l === null || l < 1000), isToken });
|
|
46
|
+
}
|
|
47
|
+
const tokens = deployments.filter((d) => d.isToken), dead = tokens.filter((d) => d.dead && d.address !== token);
|
|
48
|
+
const others = tokens.filter((d) => d.address !== token);
|
|
49
|
+
// Who funded the deployer first.
|
|
50
|
+
let fundedBy = null;
|
|
51
|
+
const first = list.find((t) => t.to?.toLowerCase() === deployer && BigInt(t.value || '0') > 0n);
|
|
52
|
+
if (first) {
|
|
53
|
+
try {
|
|
54
|
+
provenance.push(await ensureLabels(ctx));
|
|
55
|
+
}
|
|
56
|
+
catch { }
|
|
57
|
+
const a = first.from.toLowerCase();
|
|
58
|
+
fundedBy = { address: a, label: labelOf(a) ?? describeLabels(labelsFor(ctx, a)) };
|
|
59
|
+
}
|
|
60
|
+
const reasons = [], notes = [];
|
|
61
|
+
let risk = 0;
|
|
62
|
+
if (others.length) {
|
|
63
|
+
const share = dead.length / others.length;
|
|
64
|
+
reasons.push(`the deployer made ${others.length} other token${others.length > 1 ? 's' : ''}; ${dead.length} ${dead.length === 1 ? 'has' : 'have'} no pool or under $1,000 of liquidity today`);
|
|
65
|
+
if (others.length >= 3 && share >= 0.7)
|
|
66
|
+
risk += 70;
|
|
67
|
+
else if (dead.length >= 2)
|
|
68
|
+
risk += 35;
|
|
69
|
+
}
|
|
70
|
+
const age = list[0] ? (now.getTime() - Number(list[0].timeStamp) * 1000) / 86_400_000 : null;
|
|
71
|
+
if (age !== null && age < 7) {
|
|
72
|
+
risk += 15;
|
|
73
|
+
reasons.push(`the deployer wallet is ${Math.max(0, Math.round(age))} days old`);
|
|
74
|
+
}
|
|
75
|
+
if (fundedBy?.label && /tornado|mixer|railgun/i.test(fundedBy.label)) {
|
|
76
|
+
risk += 30;
|
|
77
|
+
reasons.push(`the deployer was first funded from a mixer (${fundedBy.label})`);
|
|
78
|
+
}
|
|
79
|
+
else if (fundedBy?.label)
|
|
80
|
+
notes.push(`First funded by ${fundedBy.label}.`);
|
|
81
|
+
if (!others.length)
|
|
82
|
+
notes.push('No other deployments in the creator\'s own transactions. Tokens made through a launchpad factory are created by the factory and do not show here.');
|
|
83
|
+
if (list.length >= 1000)
|
|
84
|
+
notes.push('The deployer has more than 1,000 transactions; only the first 1,000 were read.');
|
|
85
|
+
risk = Math.min(100, risk);
|
|
86
|
+
const verdict = risk >= 70 ? 'serial rug deployer' : risk >= 35 ? 'many dead tokens' : age !== null && age < 7 ? 'new deployer' : 'no bad record found';
|
|
87
|
+
const advice = risk >= 35 ? ['Most of this deployer\'s earlier tokens are dead. Expect the same unless something is clearly different this time.', 'Check what the owner can still do: oculon contract <token>'] : ['Nothing in the deployer\'s record stands out. Check the contract too: oculon contract <token>'];
|
|
88
|
+
const signals = risk >= 70 ? [{ id: signalId('deployer', deployer, c.key), module: 'deployer', title: `Deployer ${deployer.slice(0, 10)}: ${dead.length} of ${others.length} earlier tokens dead`, score: risk, entity: `deployer:${deployer}`, evidence: [{ source: 'etherscan', text: reasons[0] ?? '' }], createdAt: now.toISOString() }] : [];
|
|
89
|
+
return { module: 'deployer', input: token, generatedAt: now.toISOString(), signals, provenance, result: { ...base, deployer, createdAt, verdict, risk, deployments: deployments.reverse(), tokens: tokens.length, dead: dead.length, fundedBy, reasons, notes, advice } };
|
|
90
|
+
}
|
package/dist/modules/doc.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface DocIban {
|
|
|
8
8
|
}
|
|
9
9
|
export interface DocResult {
|
|
10
10
|
name: string;
|
|
11
|
-
type: 'pdf' | 'jpeg' | 'png';
|
|
11
|
+
type: 'pdf' | 'jpeg' | 'png' | 'docx' | 'xlsx' | 'pptx' | 'office (legacy)';
|
|
12
12
|
bytes: number;
|
|
13
13
|
sha256: string;
|
|
14
14
|
verdict: 'dangerous file' | 'likely edited' | 'signs of editing' | 'no signs of editing found';
|
|
@@ -25,6 +25,13 @@ export interface DocResult {
|
|
|
25
25
|
excerpt: string;
|
|
26
26
|
from: 'text layer' | 'ocr' | 'none';
|
|
27
27
|
};
|
|
28
|
+
/** Office files: macros, external links, embedded objects and hidden sheets found in the package. */
|
|
29
|
+
office?: {
|
|
30
|
+
macros: boolean;
|
|
31
|
+
external: string[];
|
|
32
|
+
embedded: string[];
|
|
33
|
+
hiddenSheets: string[];
|
|
34
|
+
};
|
|
28
35
|
ibans: DocIban[];
|
|
29
36
|
domains: string[];
|
|
30
37
|
advice: string[];
|
|
@@ -37,6 +44,7 @@ interface PdfObj {
|
|
|
37
44
|
/** Raw stream bytes as stored (for images). */
|
|
38
45
|
raw: Buffer | null;
|
|
39
46
|
}
|
|
47
|
+
export declare function inflate(b: Buffer): Buffer | null;
|
|
40
48
|
/** Objects of a PDF, including those packed in object streams. Streams are decoded when they use FlateDecode. */
|
|
41
49
|
export declare function pdfObjects(buf: Buffer): PdfObj[];
|
|
42
50
|
/** A PDF string value: (literal) with escapes, or <hex>, UTF-16 when it starts with a byte order mark. */
|
|
@@ -56,6 +64,20 @@ export declare function contentText(c: string, fonts: Map<string, PdfFont>): {
|
|
|
56
64
|
text: string;
|
|
57
65
|
whiteBoxes: number;
|
|
58
66
|
};
|
|
59
|
-
|
|
67
|
+
export declare function jpegMeta(b: Buffer): {
|
|
68
|
+
meta: Record<string, string>;
|
|
69
|
+
};
|
|
70
|
+
export declare function pngMeta(b: Buffer): {
|
|
71
|
+
meta: Record<string, string>;
|
|
72
|
+
};
|
|
73
|
+
export declare const IMAGE_EDITORS: RegExp;
|
|
74
|
+
export declare function officeScan(b: Buffer, type: DocResult['type'], nowMs: number): {
|
|
75
|
+
flags: [string, number][];
|
|
76
|
+
notes: string[];
|
|
77
|
+
metadata: Record<string, string>;
|
|
78
|
+
danger: boolean;
|
|
79
|
+
text: string;
|
|
80
|
+
office: NonNullable<DocResult['office']>;
|
|
81
|
+
};
|
|
60
82
|
export declare function docCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<DocResult>>;
|
|
61
83
|
export {};
|
package/dist/modules/doc.js
CHANGED
|
@@ -14,8 +14,9 @@ import { inflateSync, constants as zc } from 'node:zlib';
|
|
|
14
14
|
import { key } from '../core/keys.js';
|
|
15
15
|
import { signalId } from '../core/text.js';
|
|
16
16
|
import { checkIban } from './iban.js';
|
|
17
|
+
import { zipEntries, zipRead } from '../core/zip.js';
|
|
17
18
|
export const DOC_MAX_BYTES = 10 * 1024 * 1024;
|
|
18
|
-
function inflate(b) {
|
|
19
|
+
export function inflate(b) {
|
|
19
20
|
try {
|
|
20
21
|
return inflateSync(b, { finishFlush: zc.Z_SYNC_FLUSH });
|
|
21
22
|
}
|
|
@@ -398,7 +399,7 @@ function xmpFields(x) {
|
|
|
398
399
|
out['saves in history'] = String(saves);
|
|
399
400
|
return out;
|
|
400
401
|
}
|
|
401
|
-
function jpegMeta(b) {
|
|
402
|
+
export function jpegMeta(b) {
|
|
402
403
|
const meta = {};
|
|
403
404
|
let i = 2;
|
|
404
405
|
while (i + 4 < b.length && b[i] === 0xff) {
|
|
@@ -419,7 +420,7 @@ function jpegMeta(b) {
|
|
|
419
420
|
}
|
|
420
421
|
return { meta };
|
|
421
422
|
}
|
|
422
|
-
function pngMeta(b) {
|
|
423
|
+
export function pngMeta(b) {
|
|
423
424
|
const meta = {};
|
|
424
425
|
let i = 8;
|
|
425
426
|
while (i + 12 <= b.length) {
|
|
@@ -456,7 +457,7 @@ function pngMeta(b) {
|
|
|
456
457
|
/* ---------- what the traces mean ---------- */
|
|
457
458
|
const ONLINE_EDITORS = /ilovepdf|smallpdf|sejda|pdfescape|pdf ?candy|pdffiller|docfly|pdf2go|soda ?pdf|xodo|pdf24|hipdf|pdfzorro|online2pdf|lightpdf|pdfsimpli/i;
|
|
458
459
|
const DESKTOP_EDITORS = /pdf-xchange editor|foxit (pdf )?editor|phantompdf|nitro|pdfelement|wondershare|master pdf editor|pdf studio|inkscape|libreoffice draw|qoppa|able2extract|acrobat (pro|dc)|adobe acrobat(?! distiller)/i;
|
|
459
|
-
const IMAGE_EDITORS = /photoshop|gimp|canva|illustrator|picsart|snapseed|lightroom|pixlr|paint\.net|fotor|affinity|photopea|corel/i;
|
|
460
|
+
export const IMAGE_EDITORS = /photoshop|gimp|canva|illustrator|picsart|snapseed|lightroom|pixlr|paint\.net|fotor|affinity|photopea|corel/i;
|
|
460
461
|
const WORD_PROCESSORS = /microsoft.{0,10}word|microsoft.{0,10}excel|google docs|libreoffice writer|openoffice|pages|wps (writer|office)/i;
|
|
461
462
|
function editorFlag(label, v, flags) {
|
|
462
463
|
if (ONLINE_EDITORS.test(v))
|
|
@@ -521,6 +522,118 @@ async function ocr(ctx, img, mime, provenance) {
|
|
|
521
522
|
return null;
|
|
522
523
|
}
|
|
523
524
|
/** Check one document. `name` is only used for display. */
|
|
525
|
+
/* ---------- Office files ---------- */
|
|
526
|
+
function officeType(b) {
|
|
527
|
+
if (b.readUInt32BE(0) === 0xd0cf11e0)
|
|
528
|
+
return 'office (legacy)';
|
|
529
|
+
if (b.readUInt32LE(0) !== 0x04034b50)
|
|
530
|
+
return null;
|
|
531
|
+
try {
|
|
532
|
+
const names = zipEntries(b).map((e) => e.name);
|
|
533
|
+
if (!names.includes('[Content_Types].xml'))
|
|
534
|
+
return null;
|
|
535
|
+
return names.some((n) => n.startsWith('word/')) ? 'docx' : names.some((n) => n.startsWith('xl/')) ? 'xlsx' : names.some((n) => n.startsWith('ppt/')) ? 'pptx' : null;
|
|
536
|
+
}
|
|
537
|
+
catch {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
const xmlText = (x, tag) => [...x.matchAll(new RegExp(`<${tag}(?: [^>]*)?>([^<]*)</${tag}>`, 'g'))].map((m) => m[1]).join(' ');
|
|
542
|
+
const xmlUnescape = (s) => s.replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&');
|
|
543
|
+
export function officeScan(b, type, nowMs) {
|
|
544
|
+
const flags = [], notes = [], metadata = {};
|
|
545
|
+
const office = { macros: false, external: [], embedded: [], hiddenSheets: [] };
|
|
546
|
+
let danger = false;
|
|
547
|
+
if (type === 'office (legacy)') {
|
|
548
|
+
const s = b.toString('latin1');
|
|
549
|
+
office.macros = /_VBA_PROJECT|VBA\0|Attribute VB_Name/.test(s);
|
|
550
|
+
if (office.macros) {
|
|
551
|
+
danger = true;
|
|
552
|
+
flags.push(['contains VBA macros: code that runs when you enable content', 70]);
|
|
553
|
+
}
|
|
554
|
+
if (/DDEAUTO|\bDDE\b\s/.test(s)) {
|
|
555
|
+
danger = true;
|
|
556
|
+
flags.push(['contains a DDE field that can start programs', 60]);
|
|
557
|
+
}
|
|
558
|
+
if (/Excel 4\.0|\bEXEC\(|\bCALL\(/.test(s) && /Macro/.test(s)) {
|
|
559
|
+
danger = true;
|
|
560
|
+
flags.push(['contains Excel 4.0 macros', 60]);
|
|
561
|
+
}
|
|
562
|
+
notes.push('Old binary Office format (.doc / .xls): only macros and DDE are checked. Ask for a PDF instead.');
|
|
563
|
+
return { flags, notes, metadata, danger, text: '', office };
|
|
564
|
+
}
|
|
565
|
+
const entries = zipEntries(b);
|
|
566
|
+
const read = (n) => { const e = entries.find((x) => x.name === n); return e ? zipRead(b, e)?.toString('utf8') ?? '' : ''; };
|
|
567
|
+
const names = entries.map((e) => e.name);
|
|
568
|
+
if (names.some((n) => /vbaProject\.bin$/i.test(n)) || /macroEnabled/i.test(read('[Content_Types].xml'))) {
|
|
569
|
+
office.macros = true;
|
|
570
|
+
danger = true;
|
|
571
|
+
flags.push(['contains VBA macros: code that runs when you enable content. Invoices and statements never need macros', 70]);
|
|
572
|
+
}
|
|
573
|
+
if (names.some((n) => n.startsWith('xl/macrosheets/'))) {
|
|
574
|
+
danger = true;
|
|
575
|
+
flags.push(['contains Excel 4.0 macro sheets, a common malware trick', 70]);
|
|
576
|
+
}
|
|
577
|
+
if (names.some((n) => /\/activeX\//.test(n)))
|
|
578
|
+
flags.push(['contains ActiveX controls', 25]);
|
|
579
|
+
for (const n of names.filter((x) => /\/embeddings\//.test(x)).slice(0, 8))
|
|
580
|
+
office.embedded.push(n.split('/').pop());
|
|
581
|
+
if (office.embedded.length)
|
|
582
|
+
flags.push([`embeds ${office.embedded.length} object${office.embedded.length > 1 ? 's' : ''} (${office.embedded.slice(0, 3).join(', ')}): a file or program hidden inside the document`, office.embedded.some((e) => /\.(exe|bin|scr|js|vbs|ps1|bat|hta)$/i.test(e)) ? 40 : 15]);
|
|
583
|
+
for (const n of names.filter((x) => x.endsWith('.rels'))) {
|
|
584
|
+
for (const m of read(n).matchAll(/<Relationship\b([^>]*)\/?>/g)) {
|
|
585
|
+
const attrs = m[1];
|
|
586
|
+
if (!/TargetMode="External"/.test(attrs))
|
|
587
|
+
continue;
|
|
588
|
+
const target = xmlUnescape(/Target="([^"]*)"/.exec(attrs)?.[1] ?? '');
|
|
589
|
+
const rel = /Type="[^"]*\/([^"/]+)"/.exec(attrs)?.[1] ?? '';
|
|
590
|
+
if (/attachedTemplate|oleObject|frame|subDocument/i.test(rel)) {
|
|
591
|
+
danger = true;
|
|
592
|
+
flags.push([`loads ${rel} from outside the file (${target.slice(0, 80)}): remote template injection, used to run code`, 65]);
|
|
593
|
+
}
|
|
594
|
+
if (office.external.length < 12)
|
|
595
|
+
office.external.push(`${rel}: ${target.slice(0, 120)}`);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
const main = type === 'docx' ? read('word/document.xml') : '';
|
|
599
|
+
if (/DDEAUTO|instr="\s*DDE\b|<w:instrText[^>]*>\s*DDE/i.test(main)) {
|
|
600
|
+
danger = true;
|
|
601
|
+
flags.push(['contains a DDE field that can start programs', 60]);
|
|
602
|
+
}
|
|
603
|
+
if (/<w:instrText[^>]*>\s*(INCLUDEPICTURE|INCLUDETEXT|LINK)\b[^<]*https?:/i.test(main))
|
|
604
|
+
flags.push(['fields load content from the internet when opened (can reveal that you opened it)', 15]);
|
|
605
|
+
if (type === 'xlsx') {
|
|
606
|
+
for (const m of read('xl/workbook.xml').matchAll(/<sheet\b[^>]*name="([^"]*)"[^>]*state="(hidden|veryHidden)"/g))
|
|
607
|
+
office.hiddenSheets.push(`${xmlUnescape(m[1])} (${m[2]})`);
|
|
608
|
+
if (office.hiddenSheets.length)
|
|
609
|
+
flags.push([`${office.hiddenSheets.length} hidden sheet${office.hiddenSheets.length > 1 ? 's' : ''}: ${office.hiddenSheets.slice(0, 3).join(', ')}`, office.hiddenSheets.some((h) => /veryHidden/.test(h)) ? 30 : 10]);
|
|
610
|
+
}
|
|
611
|
+
// Metadata.
|
|
612
|
+
const core = read('docProps/core.xml'), app = read('docProps/app.xml');
|
|
613
|
+
for (const [tag, label] of [['dc:creator', 'author'], ['cp:lastModifiedBy', 'last saved by'], ['dcterms:created', 'created'], ['dcterms:modified', 'modified'], ['cp:revision', 'revision'], ['dc:title', 'title']]) {
|
|
614
|
+
const v = xmlText(core, tag).trim();
|
|
615
|
+
if (v)
|
|
616
|
+
metadata[label] = xmlUnescape(v).slice(0, 120);
|
|
617
|
+
}
|
|
618
|
+
for (const [tag, label] of [['Application', 'application'], ['AppVersion', 'app version'], ['Company', 'company'], ['TotalTime', 'editing minutes']]) {
|
|
619
|
+
const v = xmlText(app, tag).trim();
|
|
620
|
+
if (v)
|
|
621
|
+
metadata[label] = xmlUnescape(v).slice(0, 120);
|
|
622
|
+
}
|
|
623
|
+
if (metadata.author && metadata['last saved by'] && metadata.author !== metadata['last saved by'])
|
|
624
|
+
flags.push([`written by "${metadata.author}" and last saved by "${metadata['last saved by']}"`, 8]);
|
|
625
|
+
const c = Date.parse(metadata.created ?? ''), mo = Date.parse(metadata.modified ?? '');
|
|
626
|
+
if (c && mo && mo - c > 86_400_000)
|
|
627
|
+
flags.push([`modified ${Math.round((mo - c) / 86_400_000)} days after it was created`, 10]);
|
|
628
|
+
if (c && c > nowMs + 86_400_000)
|
|
629
|
+
flags.push(['the creation date is in the future', 15]);
|
|
630
|
+
if (Number(metadata.revision) >= 10)
|
|
631
|
+
notes.push(`Saved ${metadata.revision} times.`);
|
|
632
|
+
notes.push('Word and Excel files are easy to change and leave little trace. For payments, ask for a PDF from the issuer and confirm bank details by phone.');
|
|
633
|
+
// Text.
|
|
634
|
+
const text = type === 'docx' ? xmlText(main, 'w:t') : type === 'xlsx' ? xmlText(read('xl/sharedStrings.xml'), 't') : names.filter((n) => /^ppt\/slides\/slide\d+\.xml$/.test(n)).slice(0, 40).map((n) => xmlText(read(n), 'a:t')).join('\n');
|
|
635
|
+
return { flags, notes, metadata, danger, text: xmlUnescape(text), office };
|
|
636
|
+
}
|
|
524
637
|
export async function docCheck(ctx, file, name = 'document') {
|
|
525
638
|
if (!file.length)
|
|
526
639
|
throw new Error('the file is empty');
|
|
@@ -528,16 +641,28 @@ export async function docCheck(ctx, file, name = 'document') {
|
|
|
528
641
|
throw new Error(`the file is larger than ${DOC_MAX_BYTES / 1024 / 1024} MB`);
|
|
529
642
|
const now = ctx.now();
|
|
530
643
|
const head = file.subarray(0, 1024).toString('latin1');
|
|
531
|
-
const type = head.includes('%PDF-') ? 'pdf' : file[0] === 0xff && file[1] === 0xd8 ? 'jpeg' : file.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) ? 'png' :
|
|
644
|
+
const type = head.includes('%PDF-') ? 'pdf' : file[0] === 0xff && file[1] === 0xd8 ? 'jpeg' : file.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) ? 'png' : officeType(file);
|
|
532
645
|
if (!type)
|
|
533
|
-
throw new Error('not a PDF, JPEG or PNG file (expected a document, a screenshot or a photo of one)');
|
|
646
|
+
throw new Error('not a PDF, Word, Excel, PowerPoint, JPEG or PNG file (expected a document, a screenshot or a photo of one)');
|
|
534
647
|
const flags = [];
|
|
535
648
|
const notes = [];
|
|
536
649
|
const metadata = {};
|
|
537
650
|
const provenance = [{ source: 'oculon-doc', url: 'local', status: 'LIVE', fetchedAt: now.toISOString(), note: 'read from the file itself, not uploaded anywhere else' }];
|
|
538
651
|
let revisions = null, signed = false, fonts = [], text = '', from = 'none';
|
|
539
652
|
let danger = false;
|
|
540
|
-
|
|
653
|
+
let office;
|
|
654
|
+
if (type === 'docx' || type === 'xlsx' || type === 'pptx' || type === 'office (legacy)') {
|
|
655
|
+
const o = officeScan(file, type, now.getTime());
|
|
656
|
+
flags.push(...o.flags);
|
|
657
|
+
notes.push(...o.notes);
|
|
658
|
+
Object.assign(metadata, o.metadata);
|
|
659
|
+
danger = o.danger;
|
|
660
|
+
text = o.text;
|
|
661
|
+
if (text)
|
|
662
|
+
from = 'text layer';
|
|
663
|
+
office = o.office;
|
|
664
|
+
}
|
|
665
|
+
else if (type === 'pdf') {
|
|
541
666
|
const raw = file.toString('latin1');
|
|
542
667
|
const objs = pdfObjects(file);
|
|
543
668
|
const all = objs.map((o) => o.dict).join('\n');
|
|
@@ -707,6 +832,7 @@ export async function docCheck(ctx, file, name = 'document') {
|
|
|
707
832
|
ibans: found.ibans,
|
|
708
833
|
domains: found.domains,
|
|
709
834
|
advice,
|
|
835
|
+
...(office ? { office } : {}),
|
|
710
836
|
};
|
|
711
837
|
const signals = risk >= 50 || danger
|
|
712
838
|
? [{ id: signalId('doc', result.sha256), module: 'doc', title: `Document ${result.name}: ${verdict}`, score: risk, entity: `doc:${result.sha256.slice(0, 16)}`, evidence: result.flags.slice(0, 4).map((t) => ({ source: 'oculon-doc', text: t })), createdAt: now.toISOString() }]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { ModuleResult } from '../core/types.js';
|
|
3
|
+
import { type Tone } from '../core/verdict.js';
|
|
4
|
+
export interface EmlPart {
|
|
5
|
+
name: string;
|
|
6
|
+
type: string;
|
|
7
|
+
bytes: number;
|
|
8
|
+
sha256: string;
|
|
9
|
+
check: string;
|
|
10
|
+
verdict: string | null;
|
|
11
|
+
tone: Tone;
|
|
12
|
+
points: string[];
|
|
13
|
+
}
|
|
14
|
+
export interface EmlReport {
|
|
15
|
+
subject: string | null;
|
|
16
|
+
from: string | null;
|
|
17
|
+
to: string | null;
|
|
18
|
+
date: string | null;
|
|
19
|
+
verdict: 'dangerous email' | 'likely scam' | 'suspicious' | 'no known risk found';
|
|
20
|
+
risk: number;
|
|
21
|
+
headers: {
|
|
22
|
+
verdict: string | null;
|
|
23
|
+
tone: Tone;
|
|
24
|
+
points: string[];
|
|
25
|
+
} | null;
|
|
26
|
+
body: {
|
|
27
|
+
verdict: string | null;
|
|
28
|
+
tone: Tone;
|
|
29
|
+
points: string[];
|
|
30
|
+
links: number;
|
|
31
|
+
} | null;
|
|
32
|
+
attachments: EmlPart[];
|
|
33
|
+
reasons: string[];
|
|
34
|
+
advice: string[];
|
|
35
|
+
}
|
|
36
|
+
interface Part {
|
|
37
|
+
headers: Record<string, string>;
|
|
38
|
+
body: Buffer;
|
|
39
|
+
}
|
|
40
|
+
/** Leaf parts of a MIME message, depth-first. */
|
|
41
|
+
export declare function mimeParts(raw: Buffer, depth?: number): {
|
|
42
|
+
head: Record<string, string>;
|
|
43
|
+
parts: Part[];
|
|
44
|
+
};
|
|
45
|
+
export declare function emlCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<EmlReport>>;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Email file check: one .eml file (Gmail "Download message", Outlook "Save as", Apple Mail) checked in full.
|
|
3
|
+
* Headers: SPF, DKIM, DMARC, the delivery path and spoofing signs (the email header check).
|
|
4
|
+
* Body: the text and HTML parts go through the scam check (every link, the sender, known scam patterns).
|
|
5
|
+
* Attachments: PDF and Office files through the document check, images through the QR reader (QR codes in
|
|
6
|
+
* emails are a common way past link filters) and the image check, everything else hashed and looked up as
|
|
7
|
+
* known malware. Risky types (programs, scripts, disk images, HTML attachments) are flagged by name.
|
|
8
|
+
* MIME is parsed here: multipart, base64, quoted-printable and encoded-word headers.
|
|
9
|
+
*/
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { verdictOf } from '../core/verdict.js';
|
|
12
|
+
import { headerCheck } from './headers.js';
|
|
13
|
+
import { scamCheck } from './scam.js';
|
|
14
|
+
import { docCheck } from './doc.js';
|
|
15
|
+
import { qrCheck } from './qrcheck.js';
|
|
16
|
+
import { imageCheck } from './image.js';
|
|
17
|
+
import { hashCheck } from './hashcheck.js';
|
|
18
|
+
const RISKY = /\.(exe|scr|com|pif|bat|cmd|ps1|vbs|vbe|js|jse|wsf|hta|msi|lnk|iso|img|vhd|jar|apk|html?|svg|xll|one|reg|cpl|chm)$/i;
|
|
19
|
+
function decodeWords(s) {
|
|
20
|
+
return s.replace(/=\?([^?]+)\?([bqBQ])\?([^?]*)\?=/g, (_m, cs, enc, txt) => {
|
|
21
|
+
try {
|
|
22
|
+
const buf = enc.toUpperCase() === 'B' ? Buffer.from(txt, 'base64') : Buffer.from(txt.replace(/_/g, ' ').replace(/=([0-9A-F]{2})/gi, (_x, h) => String.fromCharCode(parseInt(h, 16))), 'latin1');
|
|
23
|
+
return /utf-?8/i.test(cs) ? buf.toString('utf8') : buf.toString('latin1');
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return txt;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function parseHead(raw) {
|
|
31
|
+
const out = {};
|
|
32
|
+
for (const line of raw.replace(/\r?\n[ \t]+/g, ' ').split(/\r?\n/)) {
|
|
33
|
+
const i = line.indexOf(':');
|
|
34
|
+
if (i > 0) {
|
|
35
|
+
const k = line.slice(0, i).trim().toLowerCase();
|
|
36
|
+
if (!(k in out))
|
|
37
|
+
out[k] = line.slice(i + 1).trim();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
function decodeBody(body, enc) {
|
|
43
|
+
const e = (enc ?? '').toLowerCase();
|
|
44
|
+
if (e === 'base64')
|
|
45
|
+
return Buffer.from(body.toString('latin1').replace(/[^A-Za-z0-9+/=]/g, ''), 'base64');
|
|
46
|
+
if (e === 'quoted-printable')
|
|
47
|
+
return Buffer.from(body.toString('latin1').replace(/=\r?\n/g, '').replace(/=([0-9A-F]{2})/gi, (_m, h) => String.fromCharCode(parseInt(h, 16))), 'latin1');
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
50
|
+
/** Leaf parts of a MIME message, depth-first. */
|
|
51
|
+
export function mimeParts(raw, depth = 0) {
|
|
52
|
+
const s = raw.toString('latin1');
|
|
53
|
+
const sep = /\r?\n\r?\n/.exec(s);
|
|
54
|
+
const headRaw = sep ? s.slice(0, sep.index) : s;
|
|
55
|
+
const bodyStart = sep ? sep.index + sep[0].length : s.length;
|
|
56
|
+
const head = parseHead(headRaw);
|
|
57
|
+
const ct = head['content-type'] ?? 'text/plain';
|
|
58
|
+
const boundary = /boundary="?([^";]+)"?/i.exec(ct)?.[1];
|
|
59
|
+
if (/^multipart\//i.test(ct) && boundary && depth < 6) {
|
|
60
|
+
const body = s.slice(bodyStart);
|
|
61
|
+
const pieces = body.split(new RegExp(`\\r?\\n?--${boundary.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?:--)?[ \\t]*\\r?\\n?`)).slice(1, -1).filter((p) => p.trim());
|
|
62
|
+
const parts = pieces.flatMap((p) => mimeParts(Buffer.from(p, 'latin1'), depth + 1).parts);
|
|
63
|
+
return { head, parts };
|
|
64
|
+
}
|
|
65
|
+
return { head, parts: [{ headers: head, body: decodeBody(Buffer.from(s.slice(bodyStart), 'latin1'), head['content-transfer-encoding']) }] };
|
|
66
|
+
}
|
|
67
|
+
const textOf = (p) => { const cs = /charset="?([\w-]+)/i.exec(p.headers['content-type'] ?? '')?.[1] ?? 'utf-8'; return /utf-?8|us-ascii/i.test(cs) ? p.body.toString('utf8') : p.body.toString('latin1'); };
|
|
68
|
+
const htmlToText = (h) => h.replace(/<(script|style)[\s\S]*?<\/\1>/gi, ' ').replace(/<a\b[^>]*href=["']([^"']+)["'][^>]*>/gi, ' $1 ').replace(/<[^>]+>/g, ' ').replace(/ /g, ' ').replace(/&/g, '&').replace(/\s+/g, ' ');
|
|
69
|
+
export async function emlCheck(ctx, file, name = 'email.eml') {
|
|
70
|
+
if (!file.length)
|
|
71
|
+
throw new Error('the file is empty');
|
|
72
|
+
if (file.length > 25 * 1024 * 1024)
|
|
73
|
+
throw new Error('the email is larger than 25 MB');
|
|
74
|
+
const { head, parts } = mimeParts(file);
|
|
75
|
+
if (!head.from && !head.received && !head.subject)
|
|
76
|
+
throw new Error('not an email file (.eml): no From, Subject or Received headers');
|
|
77
|
+
const provenance = [{ source: 'oculon-eml', url: 'local', status: 'LIVE', fetchedAt: ctx.now().toISOString(), note: `${parts.length} MIME parts read here` }];
|
|
78
|
+
const signals = [];
|
|
79
|
+
const reasons = [];
|
|
80
|
+
const subject = head.subject ? decodeWords(head.subject).slice(0, 200) : null;
|
|
81
|
+
// Headers.
|
|
82
|
+
const rawHead = file.toString('latin1').split(/\r?\n\r?\n/)[0];
|
|
83
|
+
let headers = null;
|
|
84
|
+
try {
|
|
85
|
+
const h = await headerCheck(ctx, rawHead);
|
|
86
|
+
provenance.push(...h.provenance.slice(0, 3));
|
|
87
|
+
const v = verdictOf(h);
|
|
88
|
+
headers = { verdict: v.verdict, tone: v.tone, points: v.points.slice(0, 5) };
|
|
89
|
+
if (v.tone === 'bad')
|
|
90
|
+
reasons.push([`headers: ${v.verdict}${v.points[0] ? ` (${v.points[0]})` : ''}`, 40]);
|
|
91
|
+
else if (v.tone === 'warn')
|
|
92
|
+
reasons.push([`headers: ${v.verdict}${v.points[0] ? ` (${v.points[0]})` : ''}`, 15]);
|
|
93
|
+
}
|
|
94
|
+
catch { }
|
|
95
|
+
// Body text: the plain part, or the HTML part as text with its links kept.
|
|
96
|
+
const texts = parts.filter((p) => /^text\/(plain|html)/i.test(p.headers['content-type'] ?? 'text/plain') && !/attachment/i.test(p.headers['content-disposition'] ?? ''));
|
|
97
|
+
const plain = texts.find((p) => /text\/plain/i.test(p.headers['content-type'] ?? 'text/plain'));
|
|
98
|
+
const html = texts.find((p) => /text\/html/i.test(p.headers['content-type'] ?? ''));
|
|
99
|
+
const bodyText = `${head.from ? `From: ${decodeWords(head.from)}\n` : ''}${subject ? `Subject: ${subject}\n\n` : ''}${(plain ? textOf(plain) : '') + (html ? `\n${htmlToText(textOf(html))}` : '')}`.slice(0, 20_000);
|
|
100
|
+
let body = null;
|
|
101
|
+
if (bodyText.trim()) {
|
|
102
|
+
try {
|
|
103
|
+
const s = await scamCheck(ctx, bodyText);
|
|
104
|
+
provenance.push(...s.provenance.slice(0, 6));
|
|
105
|
+
signals.push(...s.signals);
|
|
106
|
+
const v = verdictOf(s);
|
|
107
|
+
const links = (s.result.links ?? []).length;
|
|
108
|
+
body = { verdict: v.verdict, tone: v.tone, points: v.points.slice(0, 6), links };
|
|
109
|
+
if (v.tone === 'bad')
|
|
110
|
+
reasons.push([`message: ${v.verdict}${v.points[0] ? ` (${v.points[0]})` : ''}`, 55]);
|
|
111
|
+
else if (v.tone === 'warn')
|
|
112
|
+
reasons.push([`message: ${v.verdict}${v.points[0] ? ` (${v.points[0]})` : ''}`, 20]);
|
|
113
|
+
}
|
|
114
|
+
catch { }
|
|
115
|
+
}
|
|
116
|
+
// Attachments.
|
|
117
|
+
const attachments = [];
|
|
118
|
+
const files = parts.filter((p) => p !== plain && p !== html && (/attachment|inline/i.test(p.headers['content-disposition'] ?? '') || /name=/i.test(p.headers['content-type'] ?? '') || !/^text\//i.test(p.headers['content-type'] ?? 'text/plain')));
|
|
119
|
+
for (const p of files.slice(0, 10)) {
|
|
120
|
+
const fname = decodeWords(/filename\*?="?([^";]+)"?/i.exec(p.headers['content-disposition'] ?? '')?.[1] ?? /name="?([^";]+)"?/i.exec(p.headers['content-type'] ?? '')?.[1] ?? 'attachment');
|
|
121
|
+
const type = (p.headers['content-type'] ?? 'application/octet-stream').split(';')[0].trim().toLowerCase();
|
|
122
|
+
const sha256 = createHash('sha256').update(p.body).digest('hex');
|
|
123
|
+
let check = 'hash', verdict = null, tone = 'info', points = [];
|
|
124
|
+
const head4 = p.body.subarray(0, 8);
|
|
125
|
+
try {
|
|
126
|
+
let r = null;
|
|
127
|
+
if (head4.toString('latin1', 0, 5) === '%PDF-' || head4.readUInt32LE(0) === 0x04034b50 && /\.(docx|docm|xlsx|xlsm|pptx)$/i.test(fname) || head4.readUInt32BE(0) === 0xd0cf11e0) {
|
|
128
|
+
check = 'document';
|
|
129
|
+
r = await docCheck(ctx, p.body, fname);
|
|
130
|
+
}
|
|
131
|
+
else if (/^image\//.test(type) || /\.(png|jpe?g|webp)$/i.test(fname)) {
|
|
132
|
+
check = 'qr code';
|
|
133
|
+
const q = await qrCheck(ctx, p.body, fname).catch(() => null);
|
|
134
|
+
if (q?.result.found)
|
|
135
|
+
r = q;
|
|
136
|
+
else {
|
|
137
|
+
check = 'image';
|
|
138
|
+
r = await imageCheck(ctx, p.body, fname).catch(() => null);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
r = await hashCheck(ctx, sha256);
|
|
143
|
+
}
|
|
144
|
+
if (r) {
|
|
145
|
+
provenance.push(...r.provenance.slice(0, 2));
|
|
146
|
+
const v = verdictOf(r);
|
|
147
|
+
verdict = v.verdict;
|
|
148
|
+
tone = v.tone;
|
|
149
|
+
points = v.points.slice(0, 4);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (e) {
|
|
153
|
+
points = [`not checked: ${e.message.slice(0, 80)}`];
|
|
154
|
+
}
|
|
155
|
+
if (RISKY.test(fname)) {
|
|
156
|
+
tone = 'bad';
|
|
157
|
+
points.unshift(`${fname.split('.').pop().toUpperCase()} attachment: a type that can run code or open a fake login page`);
|
|
158
|
+
}
|
|
159
|
+
if (tone === 'bad')
|
|
160
|
+
reasons.push([`attachment ${fname}: ${verdict ?? 'risky type'}${points[0] ? ` (${points[0]})` : ''}`, RISKY.test(fname) ? 60 : 50]);
|
|
161
|
+
else if (tone === 'warn')
|
|
162
|
+
reasons.push([`attachment ${fname}: ${verdict}`, 20]);
|
|
163
|
+
attachments.push({ name: fname.slice(0, 120), type, bytes: p.body.length, sha256, check, verdict, tone, points });
|
|
164
|
+
}
|
|
165
|
+
const risk = Math.min(100, reasons.reduce((s, [, w]) => s + w, 0));
|
|
166
|
+
const danger = attachments.some((a) => a.tone === 'bad');
|
|
167
|
+
const verdict = danger && risk >= 50 ? 'dangerous email' : risk >= 50 ? 'likely scam' : risk >= 20 ? 'suspicious' : 'no known risk found';
|
|
168
|
+
const advice = verdict === 'dangerous email'
|
|
169
|
+
? ['Do not open the attachments. Delete the email, or report it as phishing in your mail app.']
|
|
170
|
+
: verdict === 'likely scam' ? ['Do not click the links or reply. Contact the sender through a website or number you already know.'] : verdict === 'suspicious' ? ['Check with the sender through another channel before you act on it.'] : ['Nothing alarming found. Still type addresses yourself instead of clicking links for logins and payments.'];
|
|
171
|
+
return {
|
|
172
|
+
module: 'eml', input: name.slice(0, 120), generatedAt: ctx.now().toISOString(), signals, provenance,
|
|
173
|
+
result: { subject, from: head.from ? decodeWords(head.from).slice(0, 200) : null, to: head.to ? decodeWords(head.to).slice(0, 200) : null, date: head.date ?? null, verdict, risk, headers, body, attachments, reasons: reasons.sort((a, b) => b[1] - a[1]).map(([r]) => r), advice },
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File hash check: is this file known malware, a known good file, or unknown?
|
|
3
3
|
* MD5, SHA-1 or SHA-256, checked against CIRCL hashlookup (NIST NSRL and other known-software sets),
|
|
4
|
-
* MalwareBazaar and ThreatFox (abuse.ch), AlienVault OTX threat reports
|
|
4
|
+
* MalwareBazaar and ThreatFox (abuse.ch), AlienVault OTX threat reports, VirusTotal engine verdicts, and Hybrid Analysis
|
|
5
|
+
* sandbox reports (HYBRID_ANALYSIS_KEY, free): what the file did when it was run.
|
|
5
6
|
*/
|
|
6
7
|
import type { Ctx } from '../core/context.js';
|
|
7
|
-
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
import type { ModuleResult, Provenance } from '../core/types.js';
|
|
8
9
|
import { type BazaarHit, type CirclHit, type OtxPulses, type ThreatFoxHit, type VtStats } from '../sources/threatintel.js';
|
|
9
10
|
export type HashVerdict = 'malicious' | 'suspicious' | 'known good' | 'unknown';
|
|
10
11
|
export interface HashCheck {
|
|
@@ -19,10 +20,25 @@ export interface HashCheck {
|
|
|
19
20
|
threatfox: ThreatFoxHit[];
|
|
20
21
|
otx: OtxPulses | null;
|
|
21
22
|
virustotal: VtStats | null;
|
|
23
|
+
/** Hybrid Analysis sandbox: its verdict, threat score 0-100, malware family and behaviour tags. */
|
|
24
|
+
hybrid: {
|
|
25
|
+
verdict: string | null;
|
|
26
|
+
threatScore: number | null;
|
|
27
|
+
family: string | null;
|
|
28
|
+
tags: string[];
|
|
29
|
+
url: string;
|
|
30
|
+
} | null;
|
|
22
31
|
advice: string[];
|
|
23
32
|
}
|
|
33
|
+
/** Hybrid Analysis overview of a SHA-256: null when unknown there or without a key. */
|
|
34
|
+
export declare function hybridAnalysis(ctx: Ctx, sha256: string): Promise<{
|
|
35
|
+
data: HashCheck['hybrid'];
|
|
36
|
+
prov: Provenance | null;
|
|
37
|
+
}>;
|
|
24
38
|
export declare function hashAlgorithm(h: string): HashCheck['algorithm'] | null;
|
|
25
|
-
export declare function judgeHash(x: Pick<HashCheck, 'circl' | 'bazaar' | 'threatfox' | 'otx' | 'virustotal'>
|
|
39
|
+
export declare function judgeHash(x: Pick<HashCheck, 'circl' | 'bazaar' | 'threatfox' | 'otx' | 'virustotal'> & {
|
|
40
|
+
hybrid?: HashCheck['hybrid'];
|
|
41
|
+
}): {
|
|
26
42
|
verdict: HashVerdict;
|
|
27
43
|
reasons: string[];
|
|
28
44
|
};
|