oculon 0.1.6 → 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 +93 -17
- package/dist/cli/main.js +397 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/der.d.ts +2 -0
- package/dist/core/der.js +17 -0
- package/dist/core/http.d.ts +30 -1
- package/dist/core/http.js +133 -29
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -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.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/core/zip.d.ts +9 -0
- package/dist/core/zip.js +46 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +128 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +256 -6
- 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.d.ts +59 -0
- package/dist/modules/checks.js +167 -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 +83 -0
- package/dist/modules/doc.js +841 -0
- 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/utility.d.ts +27 -1
- package/dist/modules/utility.js +108 -11
- package/dist/modules/where.d.ts +63 -0
- package/dist/modules/where.js +165 -0
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +84 -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/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/docs.html +1 -1
- package/dist/web/index.html +213 -5
- 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 +15 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +16 -1
- package/dist/web/server.d.ts +13 -0
- package/dist/web/server.js +152 -13
- package/dist/web/token.html +25 -4
- package/dist/web/token.json +12 -1
- package/dist/web/utility.html +40 -14
- package/package.json +2 -2
|
@@ -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
|
};
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import { key } from '../core/keys.js';
|
|
1
2
|
import { circlHash, malwareBazaar, otx, threatFox, virusTotal } from '../sources/threatintel.js';
|
|
3
|
+
/** Hybrid Analysis overview of a SHA-256: null when unknown there or without a key. */
|
|
4
|
+
export async function hybridAnalysis(ctx, sha256) {
|
|
5
|
+
const k = key('HYBRID_ANALYSIS_KEY');
|
|
6
|
+
if (!k || !/^[a-f0-9]{64}$/.test(sha256))
|
|
7
|
+
return { data: null, prov: null };
|
|
8
|
+
const r = await ctx.http.get(`https://www.hybrid-analysis.com/api/v2/overview/${sha256}`, { source: 'hybrid-analysis', ttlSec: 86_400, retries: 0, headers: { 'api-key': k, 'user-agent': 'Falcon Sandbox', accept: 'application/json' } });
|
|
9
|
+
const d = r.data;
|
|
10
|
+
if (!d || (!d.verdict && d.threat_score == null && !d.vx_family))
|
|
11
|
+
return { data: null, prov: { ...r.prov, note: r.prov.note === 'HTTP 404' ? 'not in Hybrid Analysis' : r.prov.note } };
|
|
12
|
+
return { data: { verdict: d.verdict ?? null, threatScore: d.threat_score ?? null, family: d.vx_family ?? null, tags: (d.tags ?? []).slice(0, 8), url: `https://www.hybrid-analysis.com/sample/${sha256}` }, prov: r.prov };
|
|
13
|
+
}
|
|
2
14
|
export function hashAlgorithm(h) {
|
|
3
15
|
if (/^[a-f0-9]{32}$/i.test(h))
|
|
4
16
|
return 'md5';
|
|
@@ -37,6 +49,17 @@ export function judgeHash(x) {
|
|
|
37
49
|
else if (v.engines)
|
|
38
50
|
reasons.push(`no detections from ${v.engines} VirusTotal engines`);
|
|
39
51
|
}
|
|
52
|
+
const h = x.hybrid;
|
|
53
|
+
if (h?.verdict === 'malicious') {
|
|
54
|
+
bad = true;
|
|
55
|
+
reasons.push(`Hybrid Analysis sandbox: malicious${h.family ? ` (${h.family})` : ''}${h.threatScore != null ? `, threat score ${h.threatScore}/100` : ''}`);
|
|
56
|
+
}
|
|
57
|
+
else if (h?.verdict === 'suspicious') {
|
|
58
|
+
warn = true;
|
|
59
|
+
reasons.push(`Hybrid Analysis sandbox: suspicious${h.threatScore != null ? `, threat score ${h.threatScore}/100` : ''}`);
|
|
60
|
+
}
|
|
61
|
+
else if (h?.verdict === 'no specific threat' || h?.verdict === 'whitelisted')
|
|
62
|
+
reasons.push(`Hybrid Analysis sandbox: ${h.verdict}`);
|
|
40
63
|
if (x.otx && x.otx.count > 0) {
|
|
41
64
|
warn = true;
|
|
42
65
|
reasons.push(`mentioned in ${x.otx.count} AlienVault OTX threat report${x.otx.count === 1 ? '' : 's'}`);
|
|
@@ -53,17 +76,18 @@ export async function hashCheck(ctx, input) {
|
|
|
53
76
|
const algorithm = hashAlgorithm(hash);
|
|
54
77
|
if (!algorithm)
|
|
55
78
|
throw new Error(`not a file hash: give an MD5 (32), SHA-1 (40) or SHA-256 (64) hex hash`);
|
|
56
|
-
const [circl, mb, tf, ox, vt] = await Promise.all([
|
|
79
|
+
const [circl, mb, tf, ox, vt, ha] = await Promise.all([
|
|
57
80
|
circlHash(ctx, algorithm, hash),
|
|
58
81
|
malwareBazaar(ctx, hash),
|
|
59
82
|
algorithm === 'sha1' ? Promise.resolve({ data: [], prov: null }) : threatFox(ctx, 'hash', hash),
|
|
60
83
|
otx(ctx, 'file', hash),
|
|
61
84
|
virusTotal(ctx, 'file', hash),
|
|
85
|
+
hybridAnalysis(ctx, hash),
|
|
62
86
|
]);
|
|
63
|
-
const provenance = [circl.prov, mb.prov, ...(tf.prov ? [tf.prov] : []), ox.prov, vt.prov];
|
|
64
|
-
const part = { circl: circl.data, bazaar: mb.data, threatfox: tf.data ?? [], otx: ox.data, virustotal: vt.data };
|
|
87
|
+
const provenance = [circl.prov, mb.prov, ...(tf.prov ? [tf.prov] : []), ox.prov, vt.prov, ...(ha.prov ? [ha.prov] : [])];
|
|
88
|
+
const part = { circl: circl.data, bazaar: mb.data, threatfox: tf.data ?? [], otx: ox.data, virustotal: vt.data, hybrid: ha.data };
|
|
65
89
|
const { verdict, reasons } = judgeHash(part);
|
|
66
|
-
const family = mb.data?.signature ?? tf.data?.[0]?.malware ?? vt.data?.label ?? ox.data?.family[0] ?? null;
|
|
90
|
+
const family = mb.data?.signature ?? tf.data?.[0]?.malware ?? vt.data?.label ?? ha.data?.family ?? ox.data?.family[0] ?? null;
|
|
67
91
|
const advice = verdict === 'malicious'
|
|
68
92
|
? ['Do not open or run this file. Delete it, and if it already ran, disconnect the device and scan it.', 'Look for the same hash on other machines in your network.']
|
|
69
93
|
: verdict === 'suspicious'
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { ModuleResult } from '../core/types.js';
|
|
3
|
+
export declare const IMAGE_MAX_BYTES: number;
|
|
4
|
+
export interface ImageReport {
|
|
5
|
+
name: string;
|
|
6
|
+
type: 'jpeg' | 'png' | 'webp';
|
|
7
|
+
bytes: number;
|
|
8
|
+
sha256: string;
|
|
9
|
+
verdict: 'AI generated' | 'AI edited' | 'computer generated' | 'edited' | 'camera photo' | 'no provenance found';
|
|
10
|
+
risk: number;
|
|
11
|
+
c2pa: {
|
|
12
|
+
present: boolean;
|
|
13
|
+
generator: string | null;
|
|
14
|
+
actions: string[];
|
|
15
|
+
sourceType: string | null;
|
|
16
|
+
signers: string[];
|
|
17
|
+
} | null;
|
|
18
|
+
generator: {
|
|
19
|
+
tool: string;
|
|
20
|
+
prompt: string | null;
|
|
21
|
+
settings: string | null;
|
|
22
|
+
} | null;
|
|
23
|
+
camera: string | null;
|
|
24
|
+
software: string | null;
|
|
25
|
+
metadata: Record<string, string>;
|
|
26
|
+
reasons: string[];
|
|
27
|
+
notes: string[];
|
|
28
|
+
advice: string[];
|
|
29
|
+
}
|
|
30
|
+
/** JUMBF bytes holding the C2PA manifest store, from whichever container the image uses. */
|
|
31
|
+
export declare function c2paBytes(b: Buffer, type: ImageReport['type']): Buffer | null;
|
|
32
|
+
export declare function imageCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<ImageReport>>;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image check: was this picture made by AI, edited, or taken with a camera? Reads the file itself, offline:
|
|
3
|
+
* - C2PA Content Credentials (JPEG APP11, PNG caBX, WebP C2PA chunk): the app that signed the manifest, the
|
|
4
|
+
* actions it lists (created, edited, AI-generated), the IPTC digital source type, and the organizations named
|
|
5
|
+
* in the signing certificates (OpenAI, Adobe, Google, Microsoft, camera makers...).
|
|
6
|
+
* - IPTC / XMP digital source type (trainedAlgorithmicMedia = made by AI), and AI credit lines.
|
|
7
|
+
* - Generator parameters that image tools write into PNG text chunks (Stable Diffusion, ComfyUI, NovelAI,
|
|
8
|
+
* InvokeAI, Midjourney) with the prompt when present.
|
|
9
|
+
* - EXIF camera make and model, and editing software (Photoshop, GIMP, Canva...).
|
|
10
|
+
* Missing metadata proves nothing: most sites and chat apps strip it. The signature on a C2PA manifest is not
|
|
11
|
+
* verified cryptographically here; the report says which certificates it names.
|
|
12
|
+
*/
|
|
13
|
+
import { createHash } from 'node:crypto';
|
|
14
|
+
import { IMAGE_EDITORS, inflate, jpegMeta, pngMeta } from './doc.js';
|
|
15
|
+
import { certNames } from '../core/der.js';
|
|
16
|
+
export const IMAGE_MAX_BYTES = 15 * 1024 * 1024;
|
|
17
|
+
const SOURCE_TYPES = {
|
|
18
|
+
trainedAlgorithmicMedia: 'made by a generative AI model',
|
|
19
|
+
compositeWithTrainedAlgorithmicMedia: 'edited with generative AI (part of the image is AI)',
|
|
20
|
+
algorithmicMedia: 'made by an algorithm, without a camera',
|
|
21
|
+
digitalCapture: 'taken with a digital camera',
|
|
22
|
+
negativeFilm: 'scanned from film',
|
|
23
|
+
positiveFilm: 'scanned from film',
|
|
24
|
+
print: 'scanned from a print',
|
|
25
|
+
minorHumanEdits: 'camera image with minor edits',
|
|
26
|
+
compositeCapture: 'a composite of camera images',
|
|
27
|
+
composite: 'a composite',
|
|
28
|
+
dataDrivenMedia: 'made from data',
|
|
29
|
+
digitalArt: 'digital art made by a person',
|
|
30
|
+
virtualRecording: 'a recording of a virtual scene',
|
|
31
|
+
screenCapture: 'a screenshot',
|
|
32
|
+
};
|
|
33
|
+
/** JUMBF bytes holding the C2PA manifest store, from whichever container the image uses. */
|
|
34
|
+
export function c2paBytes(b, type) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
if (type === 'jpeg') {
|
|
37
|
+
let i = 2;
|
|
38
|
+
while (i + 4 < b.length && b[i] === 0xff) {
|
|
39
|
+
const m = b[i + 1];
|
|
40
|
+
if (m === 0xda || m === 0xd9)
|
|
41
|
+
break;
|
|
42
|
+
const len = b.readUInt16BE(i + 2);
|
|
43
|
+
// APP11 carries JUMBF: "JP" common identifier, 2-byte instance, 4-byte sequence, then the box.
|
|
44
|
+
if (m === 0xeb && b.toString('latin1', i + 4, i + 6) === 'JP')
|
|
45
|
+
parts.push(b.subarray(i + 4 + 8, i + 2 + len));
|
|
46
|
+
i += 2 + len;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (type === 'png') {
|
|
50
|
+
let i = 8;
|
|
51
|
+
while (i + 12 <= b.length) {
|
|
52
|
+
const len = b.readUInt32BE(i);
|
|
53
|
+
const t = b.toString('latin1', i + 4, i + 8);
|
|
54
|
+
if (t === 'caBX')
|
|
55
|
+
parts.push(b.subarray(i + 8, i + 8 + len));
|
|
56
|
+
if (t === 'IEND')
|
|
57
|
+
break;
|
|
58
|
+
i += 12 + len;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
let i = 12;
|
|
63
|
+
while (i + 8 <= b.length) {
|
|
64
|
+
const t = b.toString('latin1', i, i + 4), len = b.readUInt32LE(i + 4);
|
|
65
|
+
if (t === 'C2PA')
|
|
66
|
+
parts.push(b.subarray(i + 8, i + 8 + len));
|
|
67
|
+
i += 8 + len + (len & 1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const all = Buffer.concat(parts);
|
|
71
|
+
return all.length && all.includes('c2pa') ? all : null;
|
|
72
|
+
}
|
|
73
|
+
/** CBOR text value right after a text key, e.g. "claim_generator" -> "Adobe_Photoshop/26.0". */
|
|
74
|
+
function cborText(buf, k) {
|
|
75
|
+
const out = [];
|
|
76
|
+
const keyBytes = Buffer.from(k, 'latin1');
|
|
77
|
+
let at = buf.indexOf(keyBytes);
|
|
78
|
+
while (at >= 0 && out.length < 8) {
|
|
79
|
+
let p = at + keyBytes.length;
|
|
80
|
+
const head = buf[p];
|
|
81
|
+
let len = -1;
|
|
82
|
+
if (head >= 0x60 && head <= 0x77) {
|
|
83
|
+
len = head - 0x60;
|
|
84
|
+
p += 1;
|
|
85
|
+
}
|
|
86
|
+
else if (head === 0x78) {
|
|
87
|
+
len = buf[p + 1];
|
|
88
|
+
p += 2;
|
|
89
|
+
}
|
|
90
|
+
else if (head === 0x79) {
|
|
91
|
+
len = buf.readUInt16BE(p + 1);
|
|
92
|
+
p += 3;
|
|
93
|
+
}
|
|
94
|
+
if (len > 0 && len < 400) {
|
|
95
|
+
const s = buf.toString('utf8', p, p + len);
|
|
96
|
+
if (/^[\x20-\x7e -]+$/.test(s))
|
|
97
|
+
out.push(s);
|
|
98
|
+
}
|
|
99
|
+
at = buf.indexOf(keyBytes, at + 1);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function pngTexts(b) {
|
|
104
|
+
const out = {};
|
|
105
|
+
let i = 8;
|
|
106
|
+
while (i + 12 <= b.length) {
|
|
107
|
+
const len = b.readUInt32BE(i);
|
|
108
|
+
const type = b.toString('latin1', i + 4, i + 8);
|
|
109
|
+
const data = b.subarray(i + 8, i + 8 + len);
|
|
110
|
+
if (type === 'tEXt' || type === 'zTXt' || type === 'iTXt') {
|
|
111
|
+
const z = data.indexOf(0);
|
|
112
|
+
const k = data.toString('latin1', 0, z);
|
|
113
|
+
let v = '';
|
|
114
|
+
if (type === 'tEXt')
|
|
115
|
+
v = data.toString('utf8', z + 1);
|
|
116
|
+
else if (type === 'zTXt')
|
|
117
|
+
v = inflate(data.subarray(z + 2))?.toString('utf8') ?? '';
|
|
118
|
+
else {
|
|
119
|
+
const rest = data.subarray(z + 1);
|
|
120
|
+
let p = 2;
|
|
121
|
+
p = rest.indexOf(0, p) + 1;
|
|
122
|
+
p = rest.indexOf(0, p) + 1;
|
|
123
|
+
v = rest[0] === 1 ? inflate(rest.subarray(p))?.toString('utf8') ?? '' : rest.subarray(p).toString('utf8');
|
|
124
|
+
}
|
|
125
|
+
out[k] = v.slice(0, 20_000);
|
|
126
|
+
}
|
|
127
|
+
if (type === 'IEND')
|
|
128
|
+
break;
|
|
129
|
+
i += 12 + len;
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
function xmpOf(b) {
|
|
134
|
+
const s = b.toString('latin1');
|
|
135
|
+
const a = s.indexOf('<x:xmpmeta');
|
|
136
|
+
if (a < 0)
|
|
137
|
+
return '';
|
|
138
|
+
const e = s.indexOf('</x:xmpmeta>', a);
|
|
139
|
+
return Buffer.from(s.slice(a, e > a ? e + 12 : a + 60_000), 'latin1').toString('utf8');
|
|
140
|
+
}
|
|
141
|
+
export async function imageCheck(ctx, file, name = 'image') {
|
|
142
|
+
if (!file.length)
|
|
143
|
+
throw new Error('the file is empty');
|
|
144
|
+
if (file.length > IMAGE_MAX_BYTES)
|
|
145
|
+
throw new Error('the image is larger than 15 MB');
|
|
146
|
+
const type = file[0] === 0xff && file[1] === 0xd8 ? 'jpeg' : file.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])) ? 'png' : file.toString('latin1', 0, 4) === 'RIFF' && file.toString('latin1', 8, 12) === 'WEBP' ? 'webp' : null;
|
|
147
|
+
if (!type)
|
|
148
|
+
throw new Error('not a JPEG, PNG or WebP image');
|
|
149
|
+
const now = ctx.now().toISOString();
|
|
150
|
+
const reasons = [];
|
|
151
|
+
const notes = [];
|
|
152
|
+
const metadata = type === 'jpeg' ? jpegMeta(file).meta : type === 'png' ? pngMeta(file).meta : {};
|
|
153
|
+
let verdict = 'no provenance found';
|
|
154
|
+
// Content Credentials.
|
|
155
|
+
let c2pa = null;
|
|
156
|
+
const jb = c2paBytes(file, type);
|
|
157
|
+
if (jb) {
|
|
158
|
+
const gen = [...cborText(jb, 'claim_generator'), ...cborText(jb, 'name')].find((g) => /[a-z]/i.test(g) && !/^c2pa\.|^(jumbf|self)/i.test(g)) ?? null;
|
|
159
|
+
const actions = [...new Set((jb.toString('latin1').match(/c2pa\.(created|edited|opened|placed|converted|cropped|resized|filtered|color_adjustments|drawing|transcoded|repackaged|removed|published)/g) ?? []))];
|
|
160
|
+
const st = /digitalsourcetype\/([A-Za-z]+)/.exec(jb.toString('latin1'))?.[1] ?? null;
|
|
161
|
+
c2pa = { present: true, generator: gen, actions, sourceType: st ? SOURCE_TYPES[st] ?? st : null, signers: certNames(jb) };
|
|
162
|
+
reasons.push([`carries Content Credentials (C2PA)${gen ? ` written by ${gen}` : ''}${c2pa.signers.length ? `, signed with certificates naming ${c2pa.signers.slice(0, 3).join(', ')}` : ''}`, 0]);
|
|
163
|
+
if (st === 'algorithmicMedia') {
|
|
164
|
+
verdict = 'computer generated';
|
|
165
|
+
reasons.push([`the credentials say it was ${SOURCE_TYPES[st]}`, 40]);
|
|
166
|
+
}
|
|
167
|
+
else if (st === 'trainedAlgorithmicMedia') {
|
|
168
|
+
verdict = 'AI generated';
|
|
169
|
+
reasons.push([`the credentials say it was ${SOURCE_TYPES[st]}`, 80]);
|
|
170
|
+
}
|
|
171
|
+
else if (st === 'compositeWithTrainedAlgorithmicMedia') {
|
|
172
|
+
verdict = 'AI edited';
|
|
173
|
+
reasons.push([`the credentials say it was ${SOURCE_TYPES[st]}`, 60]);
|
|
174
|
+
}
|
|
175
|
+
else if (st === 'digitalCapture' && !actions.some((a) => a !== 'c2pa.created' && a !== 'c2pa.opened')) {
|
|
176
|
+
verdict = 'camera photo';
|
|
177
|
+
reasons.push(['the credentials say it was taken with a camera and list no edits', 0]);
|
|
178
|
+
}
|
|
179
|
+
if (actions.some((a) => /edited|placed|drawing|filtered|removed|color_adjustments|cropped/.test(a)) && !/^(AI|computer)/.test(verdict)) {
|
|
180
|
+
verdict = 'edited';
|
|
181
|
+
reasons.push([`the credentials list edits: ${actions.filter((a) => a !== 'c2pa.opened').map((a) => a.slice(5)).join(', ')}`, 35]);
|
|
182
|
+
}
|
|
183
|
+
if (/openai|dall.?e|chatgpt|sora/i.test(`${gen} ${c2pa.signers.join(' ')}`) && verdict === 'no provenance found') {
|
|
184
|
+
verdict = 'AI generated';
|
|
185
|
+
reasons.push(['made by an OpenAI image tool, by its credentials', 80]);
|
|
186
|
+
}
|
|
187
|
+
if (/firefly|imagen|gemini|bing image|designer|midjourney|meta ai/i.test(`${gen}`) && verdict === 'no provenance found') {
|
|
188
|
+
verdict = 'AI generated';
|
|
189
|
+
reasons.push([`made by ${gen}`, 75]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// IPTC / XMP digital source type.
|
|
193
|
+
const xmp = xmpOf(file);
|
|
194
|
+
const xst = /DigitalSourceType(?:="|>)[^"<]*digitalsourcetype\/([A-Za-z]+)/i.exec(xmp)?.[1];
|
|
195
|
+
if (xst && verdict === 'no provenance found') {
|
|
196
|
+
if (xst === 'algorithmicMedia') {
|
|
197
|
+
verdict = 'computer generated';
|
|
198
|
+
reasons.push([`IPTC metadata says it was ${SOURCE_TYPES[xst]}`, 40]);
|
|
199
|
+
}
|
|
200
|
+
else if (xst === 'trainedAlgorithmicMedia') {
|
|
201
|
+
verdict = 'AI generated';
|
|
202
|
+
reasons.push([`IPTC metadata says it was ${SOURCE_TYPES[xst]}`, 75]);
|
|
203
|
+
}
|
|
204
|
+
else if (xst === 'compositeWithTrainedAlgorithmicMedia') {
|
|
205
|
+
verdict = 'AI edited';
|
|
206
|
+
reasons.push([`IPTC metadata says it was ${SOURCE_TYPES[xst]}`, 55]);
|
|
207
|
+
}
|
|
208
|
+
else
|
|
209
|
+
reasons.push([`IPTC metadata says it was ${SOURCE_TYPES[xst] ?? xst}`, 0]);
|
|
210
|
+
}
|
|
211
|
+
const credit = /(?:photoshop:Credit|Iptc4xmpCore:CreditLine|dc:creator)[^>]*>(?:\s*<rdf:\w+>\s*<rdf:li[^>]*>)?([^<]{2,120})/i.exec(xmp)?.[1]?.trim();
|
|
212
|
+
if (credit && /made with|generated|google ai|ai generated|imagen|firefly|midjourney/i.test(credit)) {
|
|
213
|
+
if (verdict === 'no provenance found')
|
|
214
|
+
verdict = 'AI generated';
|
|
215
|
+
reasons.push([`credit line: "${credit}"`, 60]);
|
|
216
|
+
}
|
|
217
|
+
// Generator parameters in PNG text.
|
|
218
|
+
let generator = null;
|
|
219
|
+
if (type === 'png') {
|
|
220
|
+
const t = pngTexts(file);
|
|
221
|
+
if (t.parameters) {
|
|
222
|
+
const [prompt, ...rest] = t.parameters.split(/\nNegative prompt:|\nSteps:/);
|
|
223
|
+
const model = /Model: ([^,\n]+)/.exec(t.parameters)?.[1];
|
|
224
|
+
generator = { tool: `Stable Diffusion${model ? ` (${model.trim()})` : ''}`, prompt: prompt?.trim().slice(0, 400) ?? null, settings: /Steps:[^\n]+/.exec(t.parameters)?.[0]?.slice(0, 300) ?? (rest.length ? 'present' : null) };
|
|
225
|
+
}
|
|
226
|
+
else if (t.workflow || (t.prompt && /class_type/.test(t.prompt))) {
|
|
227
|
+
const texts = [...(t.prompt ?? '').matchAll(/"text":\s*"((?:[^"\\]|\\.){3,400})"/g)].map((m) => m[1]);
|
|
228
|
+
generator = { tool: 'ComfyUI', prompt: texts[0] ?? null, settings: 'workflow embedded' };
|
|
229
|
+
}
|
|
230
|
+
else if (/novelai/i.test(t.Software ?? '') || /novelai/i.test(t.Source ?? '')) {
|
|
231
|
+
generator = { tool: 'NovelAI', prompt: t.Description?.slice(0, 400) ?? null, settings: t.Comment ? 'present' : null };
|
|
232
|
+
}
|
|
233
|
+
else if (t.invokeai_metadata || t['sd-metadata'] || t.Dream) {
|
|
234
|
+
generator = { tool: 'InvokeAI', prompt: /"positive_prompt":\s*"([^"]{1,400})"/.exec(t.invokeai_metadata ?? '')?.[1] ?? null, settings: 'present' };
|
|
235
|
+
}
|
|
236
|
+
else if (/midjourney/i.test(`${t.Author ?? ''} ${t.Description ?? ''} ${t.Software ?? ''}`) || /Job ID: [0-9a-f-]{36}/.test(t.Description ?? '')) {
|
|
237
|
+
generator = { tool: 'Midjourney', prompt: t.Description?.replace(/\s*Job ID:.*$/s, '').slice(0, 400) ?? null, settings: null };
|
|
238
|
+
}
|
|
239
|
+
if (generator) {
|
|
240
|
+
verdict = 'AI generated';
|
|
241
|
+
reasons.push([`the file holds ${generator.tool} generation settings${generator.prompt ? ' and the prompt' : ''}`, 85]);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (/midjourney|dall.?e|stable diffusion|firefly|leonardo|ideogram|flux|imagen/i.test(`${metadata.software ?? ''} ${metadata['creator tool'] ?? ''} ${xmp.slice(0, 4000)}`) && verdict === 'no provenance found') {
|
|
245
|
+
verdict = 'AI generated';
|
|
246
|
+
reasons.push([`the metadata names an AI image tool (${(metadata.software ?? metadata['creator tool'] ?? 'in XMP').slice(0, 60)})`, 70]);
|
|
247
|
+
}
|
|
248
|
+
// Camera and editing software.
|
|
249
|
+
const camera = [metadata.make, metadata.model].filter(Boolean).join(' ').trim() || null;
|
|
250
|
+
const software = metadata.software ?? metadata['creator tool'] ?? null;
|
|
251
|
+
if (software && IMAGE_EDITORS.test(software) && verdict !== 'AI generated') {
|
|
252
|
+
if (verdict !== 'AI edited')
|
|
253
|
+
verdict = 'edited';
|
|
254
|
+
reasons.push([`saved by an image editor (${software})`, 35]);
|
|
255
|
+
}
|
|
256
|
+
if (metadata['edit history'])
|
|
257
|
+
reasons.push([`edit history lists ${metadata['edit history']}`, 15]);
|
|
258
|
+
if (camera && verdict === 'no provenance found') {
|
|
259
|
+
verdict = 'camera photo';
|
|
260
|
+
reasons.push([`camera ${camera} recorded in EXIF`, 0]);
|
|
261
|
+
notes.push('EXIF camera data can be copied into any file; without Content Credentials it is a hint, not proof.');
|
|
262
|
+
}
|
|
263
|
+
if (verdict === 'no provenance found')
|
|
264
|
+
notes.push('No credentials, camera data or AI generator traces. Most social networks and chat apps strip metadata, so this says nothing either way; look for visual signs and find the original source with a reverse image search.');
|
|
265
|
+
const risk = Math.min(100, reasons.reduce((s, [, w]) => s + w, 0));
|
|
266
|
+
const advice = verdict === 'AI generated' || verdict === 'AI edited'
|
|
267
|
+
? ['Treat it as not a real photo. Do not use it as evidence of an event, a person or a product.']
|
|
268
|
+
: verdict === 'edited' ? ['The image was changed after it was made. Ask for the original file before relying on it.']
|
|
269
|
+
: verdict === 'camera photo' ? ['Camera data looks normal. Still check where and when it was first posted.'] : ['Search for the original (reverse image search) before you trust or share it.'];
|
|
270
|
+
const prov = [{ source: 'oculon-image', url: 'local', status: 'LIVE', fetchedAt: now, note: 'read from the file itself, not uploaded anywhere' }];
|
|
271
|
+
return {
|
|
272
|
+
module: 'image', input: name.slice(0, 120), generatedAt: now,
|
|
273
|
+
result: { name: name.slice(0, 120), type, bytes: file.length, sha256: createHash('sha256').update(file).digest('hex'), verdict, risk, c2pa, generator, camera, software, metadata, reasons: reasons.sort((a, b) => b[1] - a[1]).map(([r]) => r), notes, advice },
|
|
274
|
+
signals: [], provenance: prov,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Invite link check: what is behind a Telegram or Discord link before you join it.
|
|
3
|
+
* Telegram (t.me/name, t.me/+invite, t.me/joinchat/...): the public preview page: title, description,
|
|
4
|
+
* members or subscribers, the verified badge, and Telegram's own scam or fake label.
|
|
5
|
+
* Discord (discord.gg/code, discord.com/invite/code): the public invite API: server name, members online and
|
|
6
|
+
* total, when the server was created (from its id), verification level, partner or verified status, expiry.
|
|
7
|
+
* Flags the fake-support and fake-project pattern: a name that uses a known brand or "official", "support",
|
|
8
|
+
* "airdrop", "claim" or "recovery" without the verified badge, on a new or small server.
|
|
9
|
+
*/
|
|
10
|
+
import type { Ctx } from '../core/context.js';
|
|
11
|
+
import type { ModuleResult } from '../core/types.js';
|
|
12
|
+
export interface InviteReport {
|
|
13
|
+
link: string;
|
|
14
|
+
platform: 'telegram' | 'discord';
|
|
15
|
+
verdict: 'labeled scam' | 'likely impersonation' | 'suspicious' | 'no known risk found' | 'invite not valid';
|
|
16
|
+
risk: number;
|
|
17
|
+
name: string | null;
|
|
18
|
+
description: string | null;
|
|
19
|
+
members: number | null;
|
|
20
|
+
online: number | null;
|
|
21
|
+
verified: boolean;
|
|
22
|
+
createdAt: string | null;
|
|
23
|
+
kind: string | null;
|
|
24
|
+
reasons: string[];
|
|
25
|
+
advice: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function inviteCheck(ctx: Ctx, input: string): Promise<ModuleResult<InviteReport>>;
|