oculon 0.1.4 → 0.1.6

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.
Files changed (57) hide show
  1. package/README.md +75 -5
  2. package/dist/cli/main.js +297 -0
  3. package/dist/core/evm.d.ts +20 -0
  4. package/dist/core/evm.js +165 -0
  5. package/dist/core/http.js +7 -0
  6. package/dist/core/quota.js +23 -0
  7. package/dist/index.d.ts +36 -0
  8. package/dist/index.js +68 -0
  9. package/dist/mcp.js +81 -2
  10. package/dist/modules/address.d.ts +32 -0
  11. package/dist/modules/address.js +91 -0
  12. package/dist/modules/breach.d.ts +53 -0
  13. package/dist/modules/breach.js +98 -0
  14. package/dist/modules/company.d.ts +53 -0
  15. package/dist/modules/company.js +149 -0
  16. package/dist/modules/hashcheck.d.ts +29 -0
  17. package/dist/modules/hashcheck.js +82 -0
  18. package/dist/modules/headers.d.ts +50 -0
  19. package/dist/modules/headers.js +108 -0
  20. package/dist/modules/honeypot.d.ts +36 -0
  21. package/dist/modules/honeypot.js +53 -0
  22. package/dist/modules/iban.d.ts +30 -0
  23. package/dist/modules/iban.js +82 -0
  24. package/dist/modules/ipintel.d.ts +52 -0
  25. package/dist/modules/ipintel.js +149 -0
  26. package/dist/modules/lookalike.d.ts +34 -0
  27. package/dist/modules/lookalike.js +122 -0
  28. package/dist/modules/personal.d.ts +1 -1
  29. package/dist/modules/personal.js +14 -4
  30. package/dist/modules/phone.d.ts +32 -0
  31. package/dist/modules/phone.js +148 -0
  32. package/dist/modules/ransomware.d.ts +56 -0
  33. package/dist/modules/ransomware.js +85 -0
  34. package/dist/modules/satellites.d.ts +45 -0
  35. package/dist/modules/satellites.js +113 -0
  36. package/dist/modules/utility.d.ts +121 -0
  37. package/dist/modules/utility.js +306 -0
  38. package/dist/sources/threatintel.d.ts +151 -0
  39. package/dist/sources/threatintel.js +256 -0
  40. package/dist/telegram.d.ts +2 -0
  41. package/dist/telegram.js +93 -6
  42. package/dist/web/assets/logo-200.png +0 -0
  43. package/dist/web/burns.d.ts +21 -0
  44. package/dist/web/burns.js +53 -0
  45. package/dist/web/index.html +70 -3
  46. package/dist/web/insights.js +2 -0
  47. package/dist/web/landing.html +1 -1
  48. package/dist/web/legal.html +1 -1
  49. package/dist/web/mcp.html +1 -1
  50. package/dist/web/openapi.js +11 -0
  51. package/dist/web/public.js +13 -1
  52. package/dist/web/server.d.ts +17 -0
  53. package/dist/web/server.js +161 -4
  54. package/dist/web/token.html +97 -0
  55. package/dist/web/token.json +9 -0
  56. package/dist/web/utility.html +225 -0
  57. package/package.json +2 -2
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Breaches, from Have I Been Pwned (keyless parts, CC BY 4.0, attribution: haveibeenpwned.com).
3
+ * Password check: Pwned Passwords with k-anonymity. Only the first 5 characters of the password's SHA-1
4
+ * hash leave this machine; the match happens locally, and the password is never stored or logged.
5
+ * Breach list: the newest breaches added to HIBP, or every breach of one domain.
6
+ */
7
+ import { createHash } from 'node:crypto';
8
+ const ATTRIBUTION = 'Breach data from Have I Been Pwned (haveibeenpwned.com), CC BY 4.0.';
9
+ export const sha1Hex = (s) => createHash('sha1').update(s, 'utf8').digest('hex').toUpperCase();
10
+ /** Suffix counts for one 5-character SHA-1 prefix; padding rows (count 0) are dropped. */
11
+ export async function pwnedRange(ctx, prefix) {
12
+ const p = prefix.toUpperCase();
13
+ if (!/^[0-9A-F]{5}$/.test(p))
14
+ throw new Error('prefix must be the first 5 hex characters of a SHA-1 hash');
15
+ const r = await ctx.http.get(`https://api.pwnedpasswords.com/range/${p}`, { source: 'pwned-passwords', as: 'text', ttlSec: 7 * 86_400, headers: { 'Add-Padding': 'true' } });
16
+ if (!r.data)
17
+ return { data: null, prov: r.prov };
18
+ const m = new Map();
19
+ for (const line of r.data.split(/\r?\n/)) {
20
+ const [suf, n] = line.split(':');
21
+ const c = Number(n);
22
+ if (suf && c > 0)
23
+ m.set(suf.trim().toUpperCase(), c);
24
+ }
25
+ return { data: m, prov: r.prov };
26
+ }
27
+ /** Is this password in known breaches? Pass the password itself, or "sha1:<40 hex>". */
28
+ export async function passwordCheck(ctx, password) {
29
+ if (!password)
30
+ throw new Error('missing password');
31
+ const pre = /^sha1:([0-9a-f]{40})$/i.exec(password.trim());
32
+ const hash = pre ? pre[1].toUpperCase() : sha1Hex(password);
33
+ const r = await pwnedRange(ctx, hash.slice(0, 5));
34
+ if (!r.data)
35
+ throw new Error(`Pwned Passwords is not answering right now (${r.prov.note ?? r.prov.status})`);
36
+ const count = r.data.get(hash.slice(5)) ?? 0;
37
+ const advice = count
38
+ ? ['Stop using this password everywhere you use it, starting with email and banking.', 'Use a password manager to create a different password for every site, and turn on two-factor sign-in.']
39
+ : ['Not in any known breach. Still use it on one site only, and keep two-factor sign-in on.'];
40
+ return {
41
+ module: 'password',
42
+ // The input is never echoed: results are shown, cached and shared without the password.
43
+ input: 'password (hidden)',
44
+ generatedAt: ctx.now().toISOString(),
45
+ result: { pwned: count > 0, count, prefix: hash.slice(0, 5), advice },
46
+ signals: [],
47
+ provenance: [{ ...r.prov, note: 'only the first 5 characters of the SHA-1 hash were sent' }],
48
+ };
49
+ }
50
+ const strip = (html) => html.replace(/<[^>]+>/g, '').replace(/&quot;/g, '"').replace(/&amp;/g, '&').replace(/&#39;|&apos;/g, "'").replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/\s+/g, ' ').trim();
51
+ export function toBreach(x) {
52
+ const d = strip(x.Description ?? '');
53
+ return {
54
+ name: x.Name ?? '',
55
+ title: x.Title ?? x.Name ?? '',
56
+ domain: x.Domain || null,
57
+ breachDate: x.BreachDate ?? null,
58
+ addedDate: x.AddedDate?.slice(0, 10) ?? null,
59
+ accounts: Number(x.PwnCount ?? 0),
60
+ dataClasses: (x.DataClasses ?? []).slice(0, 12),
61
+ verified: x.IsVerified !== false,
62
+ spamList: x.IsSpamList === true,
63
+ malware: x.IsMalware === true,
64
+ description: d.length > 360 ? `${d.slice(0, 359)}…` : d,
65
+ url: `https://haveibeenpwned.com/PwnedWebsites#${encodeURIComponent(x.Name ?? '')}`,
66
+ };
67
+ }
68
+ /** Newest breaches, or the breaches of one domain or company name. Sensitive, retired and fabricated breaches are left out. */
69
+ export async function breaches(ctx, input = '') {
70
+ const q = input.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/.*$/, '');
71
+ const r = await ctx.http.get('https://haveibeenpwned.com/api/v3/breaches', {
72
+ source: 'hibp',
73
+ ttlSec: 6 * 3600,
74
+ timeoutMs: 30_000,
75
+ keep: (d) => (Array.isArray(d) ? d.filter((x) => !x.IsSensitive && !x.IsRetired && !x.IsFabricated).map((x) => ({ Name: x.Name, Title: x.Title, Domain: x.Domain, BreachDate: x.BreachDate, AddedDate: x.AddedDate, PwnCount: x.PwnCount, DataClasses: x.DataClasses, IsVerified: x.IsVerified, IsSpamList: x.IsSpamList, IsMalware: x.IsMalware, Description: (x.Description ?? '').slice(0, 1500) })) : []),
76
+ });
77
+ const provenance = [r.prov];
78
+ if (!r.data)
79
+ throw new Error(`Have I Been Pwned is not answering right now (${r.prov.note ?? r.prov.status})`);
80
+ const all = r.data.map(toBreach);
81
+ const hits = q
82
+ ? all.filter((b) => (b.domain && (b.domain === q || b.domain.endsWith(`.${q}`))) || b.name.toLowerCase() === q || b.title.toLowerCase() === q || (q.length >= 4 && !q.includes('.') && b.title.toLowerCase().includes(q)))
83
+ : all;
84
+ const sorted = [...hits].sort((a, b) => (q ? (b.breachDate ?? '').localeCompare(a.breachDate ?? '') : (b.addedDate ?? '').localeCompare(a.addedDate ?? '')));
85
+ return {
86
+ module: 'breaches',
87
+ input: q,
88
+ generatedAt: ctx.now().toISOString(),
89
+ result: {
90
+ query: q || null,
91
+ total: hits.length,
92
+ breaches: sorted.slice(0, q ? 25 : 12),
93
+ note: `${q ? (hits.length ? 'Breaches of this domain or company in Have I Been Pwned.' : 'No breach of this domain or company in Have I Been Pwned. Breaches nobody has published are not covered.') : 'The newest breaches added to Have I Been Pwned.'} ${ATTRIBUTION}`,
94
+ },
95
+ signals: [],
96
+ provenance,
97
+ };
98
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Company identity check, useful before paying an invoice or signing with a new supplier.
3
+ * EU VAT number (e.g. "NL004495445B01"): checked live with the European Commission VIES service.
4
+ * LEI (20 characters) or a company name: the Global LEI Index (GLEIF), with registered address, status,
5
+ * registration authority and ultimate parent.
6
+ * Both keyless.
7
+ */
8
+ import type { Ctx } from '../core/context.js';
9
+ import type { ModuleResult } from '../core/types.js';
10
+ export interface LeiRecord {
11
+ lei: string;
12
+ name: string;
13
+ otherNames: string[];
14
+ status: string | null;
15
+ registration: string | null;
16
+ jurisdiction: string | null;
17
+ legalForm: string | null;
18
+ registeredAs: string | null;
19
+ address: string | null;
20
+ headquarters: string | null;
21
+ country: string | null;
22
+ created: string | null;
23
+ lastUpdate: string | null;
24
+ nextRenewal: string | null;
25
+ parent: {
26
+ lei: string;
27
+ name: string;
28
+ } | null;
29
+ url: string;
30
+ }
31
+ export interface VatCheck {
32
+ country: string;
33
+ number: string;
34
+ valid: boolean;
35
+ name: string | null;
36
+ address: string | null;
37
+ checkedAt: string;
38
+ }
39
+ export interface CompanyCheck {
40
+ query: string;
41
+ kind: 'vat' | 'lei' | 'name';
42
+ vat: VatCheck | null;
43
+ records: LeiRecord[];
44
+ warnings: string[];
45
+ note: string;
46
+ }
47
+ export declare function parseVat(q: string): {
48
+ country: string;
49
+ number: string;
50
+ } | null;
51
+ /** The closest names first: exact, then "starts with", then active and issued records, then shorter names. */
52
+ export declare function rankByName(recs: LeiRecord[], q: string): LeiRecord[];
53
+ export declare function companyCheck(ctx: Ctx, input: string): Promise<ModuleResult<CompanyCheck>>;
@@ -0,0 +1,149 @@
1
+ const VAT_RE = /^(AT|BE|BG|CY|CZ|DE|DK|EE|EL|GR|ES|FI|FR|HR|HU|IE|IT|LT|LU|LV|MT|NL|PL|PT|RO|SE|SI|SK|XI)([0-9A-Z+*]{2,12})$/;
2
+ const LEI_RE = /^[A-Z0-9]{18}[0-9]{2}$/;
3
+ export function parseVat(q) {
4
+ const s = q.toUpperCase().replace(/[\s.\-]/g, '');
5
+ const m = VAT_RE.exec(s);
6
+ if (!m || !/\d/.test(m[2]))
7
+ return null;
8
+ return { country: m[1] === 'GR' ? 'EL' : m[1], number: m[2] };
9
+ }
10
+ const addr = (a) => (a ? [...(a.addressLines ?? []), [a.postalCode, a.city].filter(Boolean).join(' '), a.region, a.country].filter((x) => x && String(x).trim()).join(', ') : null) || null;
11
+ function toRecord(x) {
12
+ const a = x.attributes;
13
+ const lei = a?.lei ?? x.id;
14
+ if (!a || !lei)
15
+ return null;
16
+ const e = a.entity ?? {};
17
+ return {
18
+ lei,
19
+ name: e.legalName?.name ?? lei,
20
+ otherNames: (e.otherNames ?? []).map((n) => n.name ?? '').filter(Boolean).slice(0, 4),
21
+ status: e.status ?? null,
22
+ registration: a.registration?.status ?? null,
23
+ jurisdiction: e.jurisdiction ?? null,
24
+ // Only a written-out form; the bare ISO 20275 code (e.g. "6QQB") means nothing to a reader.
25
+ legalForm: e.legalForm?.other || null,
26
+ registeredAs: e.registeredAs ?? null,
27
+ address: addr(e.legalAddress),
28
+ headquarters: addr(e.headquartersAddress),
29
+ country: e.legalAddress?.country ?? null,
30
+ created: e.creationDate?.slice(0, 10) ?? null,
31
+ lastUpdate: a.registration?.lastUpdateDate?.slice(0, 10) ?? null,
32
+ nextRenewal: a.registration?.nextRenewalDate?.slice(0, 10) ?? null,
33
+ parent: null,
34
+ url: `https://search.gleif.org/#/record/${lei}`,
35
+ };
36
+ }
37
+ const slimRec = (d) => {
38
+ const one = (x) => ({ id: x.id, attributes: { lei: x.attributes?.lei, entity: x.attributes?.entity ? { legalName: x.attributes.entity.legalName, otherNames: x.attributes.entity.otherNames?.slice(0, 4), legalAddress: x.attributes.entity.legalAddress, headquartersAddress: x.attributes.entity.headquartersAddress, jurisdiction: x.attributes.entity.jurisdiction, legalForm: x.attributes.entity.legalForm, registeredAs: x.attributes.entity.registeredAs, status: x.attributes.entity.status, creationDate: x.attributes.entity.creationDate } : undefined, registration: x.attributes?.registration ? { status: x.attributes.registration.status, lastUpdateDate: x.attributes.registration.lastUpdateDate, nextRenewalDate: x.attributes.registration.nextRenewalDate } : undefined } });
39
+ return { data: Array.isArray(d.data) ? d.data.map(one) : d.data ? one(d.data) : undefined };
40
+ };
41
+ /** The closest names first: exact, then "starts with", then active and issued records, then shorter names. */
42
+ export function rankByName(recs, q) {
43
+ const n = (s) => s.toLowerCase().replace(/[.,]/g, '').trim();
44
+ const t = n(q);
45
+ // "Siemens Aktiengesellschaft" is the company itself; "Siemens Energy Ltd" is a subsidiary.
46
+ const FORM = /^(ag|aktiengesellschaft|se|inc|incorporated|corp|corporation|co|company|ltd|limited|plc|llc|lp|gmbh|sa|sas|sarl|spa|srl|nv|bv|as|asa|ab|oy|oyj|kk|pte ltd|pty ltd|holdings?|group)$/;
47
+ const score = (r) => {
48
+ const names = [r.name, ...r.otherNames].map(n);
49
+ const rest = names.filter((x) => x.startsWith(`${t} `)).map((x) => x.slice(t.length + 1));
50
+ return (names.includes(t) ? 8 : rest.some((x) => FORM.test(x)) ? 7 : rest.length ? 4 : names.some((x) => x.includes(t)) ? 2 : 0) + (r.status === 'ACTIVE' ? 1 : 0) + (r.registration === 'ISSUED' ? 1 : 0);
51
+ };
52
+ return [...recs].sort((a, b) => score(b) - score(a) || a.name.length - b.name.length);
53
+ }
54
+ async function vies(ctx, country, number) {
55
+ const first = await viesOnce(ctx, country, number);
56
+ // VIES often answers "too many requests to this country right now"; one short retry usually works.
57
+ if (first.data || !/CONCURRENT|SERVICE_UNAVAILABLE|TIMEOUT/.test(first.prov.note ?? ''))
58
+ return first;
59
+ if (first.prov.status !== 'CACHED')
60
+ await new Promise((r) => setTimeout(r, 2000));
61
+ return viesOnce(ctx, country, number, true);
62
+ }
63
+ async function viesOnce(ctx, country, number, fresh = false) {
64
+ const r = await ctx.http.get(`https://ec.europa.eu/taxation_customs/vies/rest-api/ms/${country}/vat/${encodeURIComponent(number)}`, { source: 'vies', ttlSec: fresh ? 0 : 24 * 3600, timeoutMs: 25_000, retries: 1 });
65
+ const d = r.data;
66
+ if (!d)
67
+ return { data: null, prov: r.prov };
68
+ if (typeof d.isValid !== 'boolean' || (d.userError && !/^(VALID|INVALID)$/.test(d.userError)))
69
+ return { data: null, prov: { ...r.prov, status: 'ERROR', note: `VIES: ${d.userError ?? 'no answer'} (the national VAT service may be down; try later)` } };
70
+ const clean = (s) => (s && s.trim() && s.trim() !== '---' ? s.replace(/\s*\n\s*/g, ', ').trim() : null);
71
+ return { data: { country, number, valid: d.isValid, name: clean(d.name), address: clean(d.address), checkedAt: d.requestDate ?? new Date().toISOString() }, prov: r.prov };
72
+ }
73
+ export async function companyCheck(ctx, input) {
74
+ const q = input.trim();
75
+ if (q.length < 2)
76
+ throw new Error('missing company name, LEI or EU VAT number');
77
+ const provenance = [];
78
+ const warnings = [];
79
+ const vatIn = parseVat(q);
80
+ const leiIn = LEI_RE.test(q.toUpperCase()) ? q.toUpperCase() : null;
81
+ let vat = null;
82
+ let records = [];
83
+ const base = 'https://api.gleif.org/api/v1/lei-records';
84
+ if (vatIn && !leiIn) {
85
+ const v = await vies(ctx, vatIn.country, vatIn.number);
86
+ provenance.push(v.prov);
87
+ if (!v.data)
88
+ throw new Error(`could not check that VAT number right now: ${v.prov.note ?? v.prov.status}`);
89
+ vat = v.data;
90
+ if (!vat.valid)
91
+ warnings.push(`VAT number ${vat.country}${vat.number} is not valid in VIES. Do not pay an invoice that quotes it until the supplier explains.`);
92
+ else if (!vat.name)
93
+ warnings.push(`The VAT number is valid, but ${vat.country === 'DE' ? 'Germany' : 'this country'} does not publish the holder's name through VIES; confirm the name with the supplier.`);
94
+ if (vat.valid && vat.name) {
95
+ const g = await ctx.http.get(`${base}?filter%5Bfulltext%5D=${encodeURIComponent(vat.name.slice(0, 80))}&filter%5Bentity.legalAddress.country%5D=${vat.country === 'EL' ? 'GR' : vat.country === 'XI' ? 'GB' : vat.country}&page%5Bsize%5D=3`, { source: 'gleif', ttlSec: 24 * 3600, keep: slimRec });
96
+ provenance.push(g.prov);
97
+ records = (g.data?.data ?? []).map(toRecord).filter((x) => x !== null);
98
+ }
99
+ }
100
+ else if (leiIn) {
101
+ const g = await ctx.http.get(`${base}/${leiIn}`, { source: 'gleif', ttlSec: 24 * 3600, keep: slimRec });
102
+ provenance.push(g.prov);
103
+ const rec = g.data?.data ? toRecord(g.data.data) : null;
104
+ if (!rec)
105
+ throw new Error(`no such LEI: ${leiIn}`);
106
+ records = [rec];
107
+ }
108
+ else {
109
+ const g = await ctx.http.get(`${base}?filter%5Bfulltext%5D=${encodeURIComponent(q.slice(0, 120))}&filter%5Bentity.category%5D=GENERAL&page%5Bsize%5D=30`, { source: 'gleif', ttlSec: 24 * 3600, keep: slimRec });
110
+ provenance.push(g.prov);
111
+ if (!g.data)
112
+ throw new Error(`GLEIF is not answering right now (${g.prov.note ?? g.prov.status})`);
113
+ records = rankByName((g.data.data ?? []).map(toRecord).filter((x) => x !== null), q).slice(0, 8);
114
+ }
115
+ let top = records[0];
116
+ if (top) {
117
+ const p = await ctx.http.get(`${base}/${top.lei}/ultimate-parent`, { source: 'gleif', ttlSec: 7 * 86_400, retries: 0, keep: slimRec });
118
+ if (p.data?.data) {
119
+ const pr = toRecord(p.data.data);
120
+ provenance.push(p.prov);
121
+ if (pr && pr.lei !== top.lei) {
122
+ const plain = (s) => s.toLowerCase().replace(/[.,]/g, '').trim();
123
+ // A name search for "Siemens" that lands on a subsidiary shows the group's parent first.
124
+ if (!leiIn && !vatIn && plain(pr.name).startsWith(plain(q))) {
125
+ records = [pr, ...records.filter((r) => r.lei !== pr.lei)].slice(0, 8);
126
+ top = pr;
127
+ }
128
+ else
129
+ top.parent = { lei: pr.lei, name: pr.name };
130
+ }
131
+ }
132
+ if (top.status === 'INACTIVE')
133
+ warnings.push(`${top.name} is marked INACTIVE in the LEI register (dissolved or merged).`);
134
+ if (top.registration === 'LAPSED')
135
+ warnings.push(`The LEI of ${top.name} has lapsed: its details were not renewed${top.nextRenewal ? ` since ${top.nextRenewal}` : ''} and may be out of date.`);
136
+ if (top.registration === 'RETIRED' || top.registration === 'ANNULLED')
137
+ warnings.push(`The LEI of ${top.name} is ${top.registration.toLowerCase()}.`);
138
+ }
139
+ if (!records.length && !vat)
140
+ warnings.push('No company with that name in the LEI register. Many small firms have no LEI, so this alone is not a warning sign.');
141
+ return {
142
+ module: 'company',
143
+ input: q,
144
+ generatedAt: ctx.now().toISOString(),
145
+ result: { query: q, kind: vatIn && !leiIn ? 'vat' : leiIn ? 'lei' : 'name', vat, records, warnings, note: 'An LEI is a global ID that companies trading in financial markets must hold. Not having one is normal for small firms.' },
146
+ signals: [],
147
+ provenance,
148
+ };
149
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * File hash check: is this file known malware, a known good file, or unknown?
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 and VirusTotal engine verdicts.
5
+ */
6
+ import type { Ctx } from '../core/context.js';
7
+ import type { ModuleResult } from '../core/types.js';
8
+ import { type BazaarHit, type CirclHit, type OtxPulses, type ThreatFoxHit, type VtStats } from '../sources/threatintel.js';
9
+ export type HashVerdict = 'malicious' | 'suspicious' | 'known good' | 'unknown';
10
+ export interface HashCheck {
11
+ hash: string;
12
+ algorithm: 'md5' | 'sha1' | 'sha256';
13
+ verdict: HashVerdict;
14
+ reasons: string[];
15
+ name: string | null;
16
+ family: string | null;
17
+ circl: CirclHit | null;
18
+ bazaar: BazaarHit | null;
19
+ threatfox: ThreatFoxHit[];
20
+ otx: OtxPulses | null;
21
+ virustotal: VtStats | null;
22
+ advice: string[];
23
+ }
24
+ export declare function hashAlgorithm(h: string): HashCheck['algorithm'] | null;
25
+ export declare function judgeHash(x: Pick<HashCheck, 'circl' | 'bazaar' | 'threatfox' | 'otx' | 'virustotal'>): {
26
+ verdict: HashVerdict;
27
+ reasons: string[];
28
+ };
29
+ export declare function hashCheck(ctx: Ctx, input: string): Promise<ModuleResult<HashCheck>>;
@@ -0,0 +1,82 @@
1
+ import { circlHash, malwareBazaar, otx, threatFox, virusTotal } from '../sources/threatintel.js';
2
+ export function hashAlgorithm(h) {
3
+ if (/^[a-f0-9]{32}$/i.test(h))
4
+ return 'md5';
5
+ if (/^[a-f0-9]{40}$/i.test(h))
6
+ return 'sha1';
7
+ if (/^[a-f0-9]{64}$/i.test(h))
8
+ return 'sha256';
9
+ return null;
10
+ }
11
+ export function judgeHash(x) {
12
+ const reasons = [];
13
+ const v = x.virustotal;
14
+ let bad = false;
15
+ let warn = false;
16
+ if (x.bazaar) {
17
+ bad = true;
18
+ reasons.push(`a MalwareBazaar sample${x.bazaar.signature ? ` of ${x.bazaar.signature}` : ''}, first seen ${x.bazaar.firstSeen?.slice(0, 10) ?? 'earlier'}`);
19
+ }
20
+ if (x.threatfox.length) {
21
+ bad = true;
22
+ reasons.push(`ThreatFox lists it as an indicator${x.threatfox[0].malware ? ` of ${x.threatfox[0].malware}` : ''}`);
23
+ }
24
+ if (x.circl?.knownMalicious) {
25
+ bad = true;
26
+ reasons.push(`CIRCL marks it as known malicious (${x.circl.knownMalicious})`);
27
+ }
28
+ if (v) {
29
+ if (v.malicious >= 5) {
30
+ bad = true;
31
+ reasons.push(`${v.malicious} of ${v.engines} VirusTotal engines detect it${v.label ? ` as ${v.label}` : ''}`);
32
+ }
33
+ else if (v.malicious > 0) {
34
+ warn = true;
35
+ reasons.push(`${v.malicious} of ${v.engines} VirusTotal engines detect it; a few detections are often false positives`);
36
+ }
37
+ else if (v.engines)
38
+ reasons.push(`no detections from ${v.engines} VirusTotal engines`);
39
+ }
40
+ if (x.otx && x.otx.count > 0) {
41
+ warn = true;
42
+ reasons.push(`mentioned in ${x.otx.count} AlienVault OTX threat report${x.otx.count === 1 ? '' : 's'}`);
43
+ }
44
+ if (x.circl?.known && !x.circl.knownMalicious)
45
+ reasons.push(`a known file in ${x.circl.sources.join(', ') || 'the CIRCL known-file sets'}${x.circl.fileName ? ` (${x.circl.fileName})` : ''}`);
46
+ const verdict = bad ? 'malicious' : warn ? 'suspicious' : x.circl?.known ? 'known good' : 'unknown';
47
+ if (verdict === 'unknown' && !reasons.length)
48
+ reasons.push('no source has seen this hash');
49
+ return { verdict, reasons };
50
+ }
51
+ export async function hashCheck(ctx, input) {
52
+ const hash = input.trim().toLowerCase();
53
+ const algorithm = hashAlgorithm(hash);
54
+ if (!algorithm)
55
+ 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([
57
+ circlHash(ctx, algorithm, hash),
58
+ malwareBazaar(ctx, hash),
59
+ algorithm === 'sha1' ? Promise.resolve({ data: [], prov: null }) : threatFox(ctx, 'hash', hash),
60
+ otx(ctx, 'file', hash),
61
+ virusTotal(ctx, 'file', hash),
62
+ ]);
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 };
65
+ const { verdict, reasons } = judgeHash(part);
66
+ const family = mb.data?.signature ?? tf.data?.[0]?.malware ?? vt.data?.label ?? ox.data?.family[0] ?? null;
67
+ const advice = verdict === 'malicious'
68
+ ? ['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
+ : verdict === 'suspicious'
70
+ ? ['Do not run it yet. Upload it to a sandbox or wait for more engines to agree before trusting it.']
71
+ : verdict === 'known good'
72
+ ? ['This matches a known software file. Make sure it came from the vendor it claims to be from.']
73
+ : ['Nobody has reported this file. That is common for new or private files, and is not proof it is safe.'];
74
+ return {
75
+ module: 'hashcheck',
76
+ input: hash,
77
+ generatedAt: ctx.now().toISOString(),
78
+ result: { hash, algorithm, verdict, reasons, name: mb.data?.fileName ?? vt.data?.name ?? circl.data?.fileName ?? null, family, ...part, advice },
79
+ signals: [],
80
+ provenance,
81
+ };
82
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Email header analysis. Paste the raw headers of a message ("Show original" in Gmail, "View source" elsewhere)
3
+ * and get what the receiving server decided about SPF, DKIM and DMARC, the path the message took, the
4
+ * server that first handed it over, and the classic spoofing tells: a From address that differs from the
5
+ * envelope sender, a Reply-To that sends answers elsewhere, a display name dressed up as an address.
6
+ * Parsing is offline; only the origin IP is looked up (ip-api.com, keyless) to say where it came from.
7
+ */
8
+ import type { Ctx } from '../core/context.js';
9
+ import type { ModuleResult } from '../core/types.js';
10
+ export interface Hop {
11
+ from: string | null;
12
+ by: string | null;
13
+ ip: string | null;
14
+ date: string | null;
15
+ }
16
+ export interface HeaderReport {
17
+ from: {
18
+ name: string | null;
19
+ address: string | null;
20
+ domain: string | null;
21
+ };
22
+ replyTo: string | null;
23
+ returnPath: string | null;
24
+ subject: string | null;
25
+ date: string | null;
26
+ messageIdDomain: string | null;
27
+ auth: {
28
+ spf: string | null;
29
+ dkim: string | null;
30
+ dmarc: string | null;
31
+ dkimDomain: string | null;
32
+ };
33
+ hops: Hop[];
34
+ origin: {
35
+ ip: string | null;
36
+ country: string | null;
37
+ isp: string | null;
38
+ hosting: boolean | null;
39
+ };
40
+ verdict: 'looks genuine' | 'suspicious' | 'likely spoofed';
41
+ risk: number;
42
+ flags: string[];
43
+ advice: string[];
44
+ }
45
+ /** Unfold continuation lines and split into [name, value] pairs, in order. */
46
+ export declare function parseHeaders(raw: string): [string, string][];
47
+ export declare function analyzeHeaders(raw: string): Omit<HeaderReport, 'origin'> & {
48
+ originIp: string | null;
49
+ };
50
+ export declare function headerCheck(ctx: Ctx, raw: string): Promise<ModuleResult<HeaderReport>>;
@@ -0,0 +1,108 @@
1
+ import { ipApi, isPublicIp } from '../sources/threatintel.js';
2
+ /** Unfold continuation lines and split into [name, value] pairs, in order. */
3
+ export function parseHeaders(raw) {
4
+ const text = raw.replace(/\r\n/g, '\n').split(/\n\n/)[0].replace(/\n[ \t]+/g, ' ');
5
+ const out = [];
6
+ for (const line of text.split('\n')) {
7
+ const m = /^([A-Za-z0-9-]+):\s*(.*)$/.exec(line);
8
+ if (m)
9
+ out.push([m[1].toLowerCase(), m[2].trim()]);
10
+ }
11
+ return out;
12
+ }
13
+ const domainOf = (addr) => (addr ? /@([^>\s]+)/.exec(addr)?.[1]?.toLowerCase().replace(/[>.]+$/, '') ?? null : null);
14
+ const addrIn = (v) => (v ? (/<([^>]+)>/.exec(v)?.[1] ?? /[^\s<>"]+@[^\s<>"]+/.exec(v)?.[0] ?? null) : null);
15
+ /** The registrable part, good enough for comparing sender domains (mail.example.com ~ example.com). */
16
+ const base = (d) => (d ? d.split('.').slice(-2).join('.') : null);
17
+ export function analyzeHeaders(raw) {
18
+ const h = parseHeaders(raw);
19
+ const get = (n) => h.find(([k]) => k === n)?.[1];
20
+ const all = (n) => h.filter(([k]) => k === n).map(([, v]) => v);
21
+ const fromRaw = get('from') ?? '';
22
+ const fromAddr = addrIn(fromRaw);
23
+ const fromName = fromRaw.includes('<') ? fromRaw.slice(0, fromRaw.indexOf('<')).replace(/"/g, '').trim() || null : null;
24
+ const replyTo = addrIn(get('reply-to'));
25
+ const returnPath = addrIn(get('return-path'));
26
+ const ar = all('authentication-results').join('; ') + '; ' + all('arc-authentication-results').join('; ');
27
+ const res = (k) => new RegExp(`\\b${k}=([a-z]+)`, 'i').exec(ar)?.[1]?.toLowerCase() ?? null;
28
+ const rspf = /^(pass|fail|softfail|neutral|none|temperror|permerror)\b/i.exec(get('received-spf') ?? '')?.[1]?.toLowerCase() ?? null;
29
+ const auth = { spf: res('spf') ?? rspf, dkim: res('dkim'), dmarc: res('dmarc'), dkimDomain: /header\.d=([^\s;]+)/i.exec(ar)?.[1]?.toLowerCase() ?? /\bd=([^\s;]+)/.exec(get('dkim-signature') ?? '')?.[1]?.toLowerCase() ?? null };
30
+ const hops = all('received').map((v) => ({
31
+ from: /\bfrom\s+([^\s(;]+)/i.exec(v)?.[1] ?? null,
32
+ by: /\bby\s+([^\s(;]+)/i.exec(v)?.[1] ?? null,
33
+ ip: /\[(\d{1,3}(?:\.\d{1,3}){3}|[0-9a-f:]{3,})\]/i.exec(v)?.[1] ?? /\((?:[^)]*?)(\d{1,3}(?:\.\d{1,3}){3})(?:[^)]*)\)/.exec(v)?.[1] ?? null,
34
+ date: v.includes(';') ? v.slice(v.lastIndexOf(';') + 1).trim() || null : null,
35
+ }));
36
+ // Received headers are newest first: the last public IP is the server that first handed the message in.
37
+ const originIp = [...hops].reverse().map((x) => x.ip).find((ip) => ip && isPublicIp(ip)) ?? null;
38
+ const fromDomain = domainOf(fromAddr);
39
+ const flags = [];
40
+ let risk = 0;
41
+ if (auth.dmarc === 'fail') {
42
+ flags.push('DMARC failed: the sending domain says this message is not from it');
43
+ risk += 45;
44
+ }
45
+ if (auth.spf === 'fail') {
46
+ flags.push('SPF failed: the sending server is not allowed to send for this domain');
47
+ risk += 25;
48
+ }
49
+ else if (auth.spf === 'softfail') {
50
+ flags.push('SPF soft fail: the sending server is not on the domain\'s list');
51
+ risk += 12;
52
+ }
53
+ if (auth.dkim === 'fail') {
54
+ flags.push('DKIM signature failed: the message may have been altered');
55
+ risk += 20;
56
+ }
57
+ if (!auth.dkim || auth.dkim === 'none') {
58
+ flags.push('no DKIM signature');
59
+ risk += 6;
60
+ }
61
+ if (auth.dkimDomain && fromDomain && base(auth.dkimDomain) !== base(fromDomain)) {
62
+ flags.push(`signed by ${auth.dkimDomain}, not by ${fromDomain}`);
63
+ risk += 10;
64
+ }
65
+ const rpDomain = domainOf(returnPath);
66
+ if (rpDomain && fromDomain && base(rpDomain) !== base(fromDomain)) {
67
+ flags.push(`envelope sender ${rpDomain} differs from the From domain ${fromDomain}`);
68
+ risk += 10;
69
+ }
70
+ const rtDomain = domainOf(replyTo);
71
+ if (rtDomain && fromDomain && base(rtDomain) !== base(fromDomain)) {
72
+ flags.push(`replies go to ${replyTo}, not to the sender`);
73
+ risk += 20;
74
+ }
75
+ if (fromName && /@/.test(fromName) && domainOf(fromName) !== fromDomain) {
76
+ flags.push(`the display name shows an address (${fromName}) that is not the real sender`);
77
+ risk += 25;
78
+ }
79
+ if (fromDomain && /^(gmail|outlook|hotmail|yahoo|proton|icloud)\./.test(fromDomain) && fromName && /\b(bank|support|security|billing|paypal|microsoft|apple|amazon|invoice|account)\b/i.test(fromName)) {
80
+ flags.push(`"${fromName}" sent from a free ${fromDomain} mailbox`);
81
+ risk += 20;
82
+ }
83
+ risk = Math.min(100, risk);
84
+ const verdict = risk >= 50 ? 'likely spoofed' : risk >= 20 ? 'suspicious' : 'looks genuine';
85
+ const advice = verdict === 'looks genuine'
86
+ ? ['The authentication checks passed. That proves which domain sent it, not that the domain is honest: check the domain itself before acting.']
87
+ : ['Do not click links, open attachments or pay anything from this message.', 'Contact the sender through an address or phone number you already have, not one in this email.'];
88
+ return {
89
+ from: { name: fromName, address: fromAddr, domain: fromDomain }, replyTo, returnPath, subject: get('subject') ?? null, date: get('date') ?? null,
90
+ messageIdDomain: domainOf(get('message-id') ?? null), auth, hops, originIp, verdict, risk, flags, advice,
91
+ };
92
+ }
93
+ export async function headerCheck(ctx, raw) {
94
+ if (!raw || !/^(received|from|return-path|delivered-to|authentication-results|dkim-signature|message-id|arc-|x-)/im.test(raw)) {
95
+ throw new Error('give the raw email headers: in Gmail open the message, choose "Show original" and copy everything above the body');
96
+ }
97
+ const a = analyzeHeaders(raw.slice(0, 200_000));
98
+ const provenance = [{ source: 'email-headers', url: 'https://www.rfc-editor.org/rfc/rfc8601', status: 'LIVE', fetchedAt: ctx.now().toISOString(), note: `${a.hops.length} Received hops parsed offline` }];
99
+ let origin = { ip: a.originIp, country: null, isp: null, hosting: null };
100
+ if (a.originIp) {
101
+ const g = await ipApi(ctx, a.originIp);
102
+ provenance.push(g.prov);
103
+ if (g.data)
104
+ origin = { ip: a.originIp, country: g.data.country ?? null, isp: g.data.isp ?? null, hosting: g.data.hosting ?? null };
105
+ }
106
+ const { originIp: _o, ...rest } = a;
107
+ return { module: 'headers', input: `${a.from.address ?? 'unknown sender'}${a.subject ? ` · ${a.subject.slice(0, 80)}` : ''}`, generatedAt: ctx.now().toISOString(), result: { ...rest, origin }, signals: [], provenance };
108
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Can this token be sold? honeypot.is (keyless) simulates a buy and a sell on the token's main pool and
3
+ * replays recent holders' sells, which catches honeypots, sell taxes that eat the position, and contracts
4
+ * that only let some wallets out. Supported chains: Ethereum, BNB Chain and Base.
5
+ * A simulation that passes today can fail tomorrow if the owner changes the contract.
6
+ */
7
+ import type { Ctx } from '../core/context.js';
8
+ import type { ModuleResult } from '../core/types.js';
9
+ export declare const HONEYPOT_CHAINS: Record<string, [number, string]>;
10
+ export interface HoneypotReport {
11
+ address: string;
12
+ chain: string;
13
+ name: string | null;
14
+ symbol: string | null;
15
+ verdict: 'honeypot' | 'high risk' | 'caution' | 'sellable';
16
+ simulated: boolean;
17
+ isHoneypot: boolean | null;
18
+ buyTax: number | null;
19
+ sellTax: number | null;
20
+ transferTax: number | null;
21
+ holders: {
22
+ checked: number;
23
+ failed: number;
24
+ siphoned: number;
25
+ highestTax: number | null;
26
+ } | null;
27
+ openSource: boolean | null;
28
+ proxy: boolean | null;
29
+ pair: string | null;
30
+ flags: string[];
31
+ reasons: string[];
32
+ advice: string[];
33
+ }
34
+ export declare function honeypotCheck(ctx: Ctx, address: string, opts?: {
35
+ chain?: string;
36
+ }): Promise<ModuleResult<HoneypotReport>>;