oculon 0.1.5 → 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.
- package/README.md +55 -3
- package/dist/cli/main.js +102 -0
- package/dist/core/evm.d.ts +20 -0
- package/dist/core/evm.js +165 -0
- package/dist/core/http.js +3 -0
- package/dist/core/quota.js +3 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +25 -0
- package/dist/mcp.js +31 -1
- package/dist/modules/address.d.ts +32 -0
- package/dist/modules/address.js +91 -0
- package/dist/modules/headers.d.ts +50 -0
- package/dist/modules/headers.js +108 -0
- package/dist/modules/honeypot.d.ts +36 -0
- package/dist/modules/honeypot.js +53 -0
- package/dist/modules/iban.d.ts +30 -0
- package/dist/modules/iban.js +82 -0
- package/dist/modules/lookalike.d.ts +34 -0
- package/dist/modules/lookalike.js +122 -0
- package/dist/modules/personal.d.ts +1 -1
- package/dist/modules/personal.js +14 -4
- package/dist/modules/utility.d.ts +121 -0
- package/dist/modules/utility.js +306 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +43 -6
- package/dist/web/assets/logo-200.png +0 -0
- package/dist/web/burns.d.ts +21 -0
- package/dist/web/burns.js +53 -0
- package/dist/web/landing.html +1 -1
- package/dist/web/legal.html +1 -1
- package/dist/web/mcp.html +1 -1
- package/dist/web/openapi.js +4 -0
- package/dist/web/public.js +5 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +129 -3
- package/dist/web/token.html +97 -0
- package/dist/web/token.json +9 -0
- package/dist/web/utility.html +225 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { screen } from './sanctions.js';
|
|
2
|
+
const B58 = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
3
|
+
export function detectChain(a) {
|
|
4
|
+
if (/^0x[0-9a-fA-F]{40}$/.test(a))
|
|
5
|
+
return { chain: 'evm', format: 'EVM (Ethereum, Base, Robinhood Chain and other EVM chains)' };
|
|
6
|
+
if (/^(bc1|tb1)[02-9ac-hj-np-z]{11,71}$/.test(a.toLowerCase()))
|
|
7
|
+
return { chain: 'bitcoin', format: a.toLowerCase().startsWith('bc1p') ? 'Bitcoin Taproot (bech32m)' : 'Bitcoin SegWit (bech32)' };
|
|
8
|
+
if (/^[13][1-9A-HJ-NP-Za-km-z]{25,34}$/.test(a))
|
|
9
|
+
return { chain: 'bitcoin', format: a.startsWith('1') ? 'Bitcoin legacy (P2PKH)' : 'Bitcoin script (P2SH)' };
|
|
10
|
+
if (/^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(a))
|
|
11
|
+
return { chain: 'tron', format: 'Tron (TRC-20 USDT lives here)' };
|
|
12
|
+
if (B58.test(a) && a.length >= 32 && a.length <= 44)
|
|
13
|
+
return { chain: 'solana', format: 'Solana' };
|
|
14
|
+
return { chain: 'unknown', format: 'not a recognized address format' };
|
|
15
|
+
}
|
|
16
|
+
export async function addressCheck(ctx, input, opts = {}) {
|
|
17
|
+
const address = input.trim();
|
|
18
|
+
if (!address)
|
|
19
|
+
throw new Error('give a crypto address');
|
|
20
|
+
const { chain, format } = detectChain(address);
|
|
21
|
+
if (chain === 'unknown')
|
|
22
|
+
throw new Error(`not a crypto address: ${address.slice(0, 60)}`);
|
|
23
|
+
const provenance = [];
|
|
24
|
+
const warnings = [];
|
|
25
|
+
let activity = null;
|
|
26
|
+
let network = null;
|
|
27
|
+
if (chain === 'bitcoin') {
|
|
28
|
+
network = 'Bitcoin';
|
|
29
|
+
const r = await ctx.http.get(`https://mempool.space/api/address/${address}`, { source: 'mempool-space', ttlSec: 600 });
|
|
30
|
+
provenance.push(r.prov);
|
|
31
|
+
const s = r.data?.chain_stats;
|
|
32
|
+
if (s)
|
|
33
|
+
activity = { txCount: s.tx_count ?? 0, balance: `${(((s.funded_txo_sum ?? 0) - (s.spent_txo_sum ?? 0)) / 1e8).toFixed(8)} BTC`, firstSeen: null, isContract: false, label: null };
|
|
34
|
+
}
|
|
35
|
+
else if (chain === 'evm') {
|
|
36
|
+
const rh = /^(rh|robinhood)$/i.test(opts.network ?? '');
|
|
37
|
+
network = rh ? 'Robinhood Chain' : 'Ethereum';
|
|
38
|
+
const base = rh ? 'https://api.blockscout.com/4663/api/v2' : 'https://eth.blockscout.com/api/v2';
|
|
39
|
+
const r = await ctx.http.get(`${base}/addresses/${address}`, { source: 'blockscout', ttlSec: 900 });
|
|
40
|
+
provenance.push(r.prov);
|
|
41
|
+
const c = await ctx.http.get(`${base}/addresses/${address}/counters`, { source: 'blockscout', ttlSec: 900 });
|
|
42
|
+
provenance.push(c.prov);
|
|
43
|
+
if (r.data || r.prov.note === 'HTTP 404') {
|
|
44
|
+
const d = r.data ?? {};
|
|
45
|
+
activity = { txCount: c.data?.transactions_count ? Number(c.data.transactions_count) : 0, balance: d.coin_balance ? `${(Number(BigInt(d.coin_balance) / 10n ** 12n) / 1e6).toFixed(6)} ETH` : '0 ETH', firstSeen: null,
|
|
46
|
+
// A wallet with an EIP-7702 delegation also has code, but no creator: only deployed contracts have one.
|
|
47
|
+
isContract: d.is_contract === undefined ? null : Boolean(d.is_contract && d.creator_address_hash),
|
|
48
|
+
label: d.ens_domain_name ?? d.public_tags?.[0]?.display_name ?? d.name ?? null };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (chain === 'solana') {
|
|
52
|
+
network = 'Solana';
|
|
53
|
+
const r = await ctx.http.postBytes('https://api.mainnet-beta.solana.com', new TextEncoder().encode(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getBalance', params: [address] })), { source: 'solana-rpc', headers: { 'content-type': 'application/json' }, timeoutMs: 20_000 });
|
|
54
|
+
provenance.push(r.prov);
|
|
55
|
+
let lamports = null;
|
|
56
|
+
try {
|
|
57
|
+
lamports = r.data ? Number(JSON.parse(r.data.toString('utf8')).result?.value ?? NaN) : null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
lamports = null;
|
|
61
|
+
}
|
|
62
|
+
if (lamports !== null && Number.isFinite(lamports))
|
|
63
|
+
activity = { txCount: null, balance: `${(lamports / 1e9).toFixed(6)} SOL`, firstSeen: null, isContract: null, label: null };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
network = 'Tron';
|
|
67
|
+
}
|
|
68
|
+
if (activity && activity.txCount === 0)
|
|
69
|
+
warnings.push('this address has never been used: double-check it with the person you are paying through another channel');
|
|
70
|
+
if (activity?.isContract)
|
|
71
|
+
warnings.push('this is a smart contract, not a personal wallet: sending to it directly can lose the funds');
|
|
72
|
+
// Sanctions: the US OFAC SDN list includes crypto addresses (Bitcoin, EVM, Tron and more).
|
|
73
|
+
let sanctioned = null;
|
|
74
|
+
const hits = [];
|
|
75
|
+
try {
|
|
76
|
+
const s = await screen(ctx, address);
|
|
77
|
+
provenance.push(...s.provenance.slice(0, 2));
|
|
78
|
+
sanctioned = s.result.verdict === 'SANCTIONED';
|
|
79
|
+
for (const h of s.result.hits.slice(0, 3))
|
|
80
|
+
hits.push(JSON.stringify(h).slice(0, 160));
|
|
81
|
+
if (sanctioned)
|
|
82
|
+
warnings.unshift('this address is on the US OFAC sanctions list: sending to it can be illegal');
|
|
83
|
+
else if (s.result.verdict === 'EXPOSED')
|
|
84
|
+
warnings.push('this address has traded directly with a sanctioned address');
|
|
85
|
+
}
|
|
86
|
+
catch { /* the list is optional here */ }
|
|
87
|
+
const advice = warnings.length
|
|
88
|
+
? ['Do not send funds until you have confirmed the address with the recipient through a channel you already trust.']
|
|
89
|
+
: ['Nothing alarming found. Still send a small test amount first, and never send to an address someone pushes on you in a chat.'];
|
|
90
|
+
return { module: 'address', input: address, generatedAt: ctx.now().toISOString(), result: { address, chain, format, network, activity, sanctioned, sanctionHits: hits, warnings, advice }, signals: [], provenance };
|
|
91
|
+
}
|
|
@@ -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>>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { signalId } from '../core/text.js';
|
|
2
|
+
export const HONEYPOT_CHAINS = { eth: [1, 'Ethereum'], ethereum: [1, 'Ethereum'], bsc: [56, 'BNB Chain'], bnb: [56, 'BNB Chain'], base: [8453, 'Base'] };
|
|
3
|
+
const flagText = (f) => (typeof f === 'string' ? f : f.description || f.flag || '');
|
|
4
|
+
export async function honeypotCheck(ctx, address, opts = {}) {
|
|
5
|
+
const a = address.trim();
|
|
6
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(a))
|
|
7
|
+
throw new Error('give a token contract address: 0x followed by 40 hex characters');
|
|
8
|
+
const key = (opts.chain ?? 'eth').toLowerCase();
|
|
9
|
+
if (key === 'robinhood' || key === 'rh')
|
|
10
|
+
throw new Error('not a supported chain for sell simulation: use "oculon token <address> --chain robinhood" for Robinhood Chain tokens');
|
|
11
|
+
const chain = HONEYPOT_CHAINS[key];
|
|
12
|
+
if (!chain)
|
|
13
|
+
throw new Error(`not a supported chain: ${key} (use eth, bsc or base)`);
|
|
14
|
+
const r = await ctx.http.get(`https://api.honeypot.is/v2/IsHoneypot?address=${a}&chainID=${chain[0]}`, { source: 'honeypot-is', ttlSec: 900, timeoutMs: 30_000, retries: 1 });
|
|
15
|
+
if (!r.data)
|
|
16
|
+
throw new Error(r.prov.note === 'HTTP 404' || r.prov.note === 'HTTP 400' ? `no pool found for ${a} on ${chain[1]}` : `honeypot.is is not answering right now (${r.prov.note ?? r.prov.status})`);
|
|
17
|
+
const d = r.data;
|
|
18
|
+
const sim = d.simulationResult ?? {};
|
|
19
|
+
const h = d.holderAnalysis;
|
|
20
|
+
const holders = h ? { checked: Number(h.holders ?? 0), failed: Number(h.failed ?? 0), siphoned: Number(h.siphoned ?? 0), highestTax: typeof h.highestTax === 'number' ? h.highestTax : null } : null;
|
|
21
|
+
const flags = [...(d.summary?.flags ?? []), ...(d.flags ?? [])].map(flagText).filter(Boolean);
|
|
22
|
+
const reasons = [];
|
|
23
|
+
const isHp = d.honeypotResult?.isHoneypot ?? null;
|
|
24
|
+
if (isHp)
|
|
25
|
+
reasons.push(`sells fail in simulation${d.honeypotResult?.honeypotReason ? `: ${d.honeypotResult.honeypotReason}` : ''}`);
|
|
26
|
+
if (d.simulationSuccess === false)
|
|
27
|
+
reasons.push(`the buy and sell could not be simulated${d.simulationError ? ` (${d.simulationError})` : ''}`);
|
|
28
|
+
const st = sim.sellTax ?? null, bt = sim.buyTax ?? null;
|
|
29
|
+
if (st !== null && st >= 10)
|
|
30
|
+
reasons.push(`sell tax ${st.toFixed(1)}%`);
|
|
31
|
+
if (bt !== null && bt >= 10)
|
|
32
|
+
reasons.push(`buy tax ${bt.toFixed(1)}%`);
|
|
33
|
+
if (holders && holders.checked && holders.failed / holders.checked > 0.05)
|
|
34
|
+
reasons.push(`${holders.failed} of ${holders.checked} recent holders could not sell`);
|
|
35
|
+
if (holders?.siphoned)
|
|
36
|
+
reasons.push(`${holders.siphoned} holder wallets had tokens taken out`);
|
|
37
|
+
if (d.contractCode?.openSource === false)
|
|
38
|
+
reasons.push('contract source is not published');
|
|
39
|
+
if (d.contractCode?.isProxy)
|
|
40
|
+
reasons.push('upgradeable proxy: the owner can change the code');
|
|
41
|
+
const risk = (d.summary?.riskLevel ?? 0);
|
|
42
|
+
const verdict = isHp ? 'honeypot' : (st ?? 0) >= 30 || risk >= 60 ? 'high risk' : reasons.length || risk >= 20 ? 'caution' : 'sellable';
|
|
43
|
+
const advice = verdict === 'sellable'
|
|
44
|
+
? ['Sells work in simulation today. That says nothing about the project itself, and the owner can still change the contract.']
|
|
45
|
+
: ['Do not buy. If you hold it, try a small sell first and do not approve unlimited spending.'];
|
|
46
|
+
const nowIso = ctx.now().toISOString();
|
|
47
|
+
const signals = verdict === 'honeypot' ? [{ id: signalId('honeypot', a.toLowerCase(), chain[1]), module: 'honeypot', title: `${d.token?.symbol ?? a.slice(0, 10)} on ${chain[1]}: sells fail in simulation`, score: 70, entity: a.toLowerCase(), evidence: [{ source: 'honeypot.is', text: reasons[0] ?? 'honeypot', url: `https://honeypot.is/?address=${a}` }], createdAt: nowIso }] : [];
|
|
48
|
+
return {
|
|
49
|
+
module: 'honeypot', input: a, generatedAt: nowIso,
|
|
50
|
+
result: { address: a, chain: chain[1], name: d.token?.name ?? null, symbol: d.token?.symbol ?? null, verdict, simulated: d.simulationSuccess === true, isHoneypot: isHp, buyTax: bt, sellTax: st, transferTax: sim.transferTax ?? null, holders, openSource: d.contractCode?.openSource ?? null, proxy: d.contractCode?.isProxy ?? null, pair: d.pair?.pair?.name ?? null, flags, reasons, advice },
|
|
51
|
+
signals, provenance: [{ ...r.prov, note: 'buy and sell simulated on the main pool' }],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IBAN check, fully offline: country, length, the ISO 13616 mod-97 check digits, the bank part of the number
|
|
3
|
+
* and, for an invoice, whether the account country matches the supplier's country.
|
|
4
|
+
* A valid IBAN only proves the number is well formed. It cannot tell who owns the account.
|
|
5
|
+
*/
|
|
6
|
+
import type { Ctx } from '../core/context.js';
|
|
7
|
+
import type { ModuleResult } from '../core/types.js';
|
|
8
|
+
export interface IbanCheck {
|
|
9
|
+
input: string;
|
|
10
|
+
iban: string | null;
|
|
11
|
+
formatted: string | null;
|
|
12
|
+
valid: boolean;
|
|
13
|
+
country: string | null;
|
|
14
|
+
countryName: string | null;
|
|
15
|
+
checkDigits: string | null;
|
|
16
|
+
bank: {
|
|
17
|
+
code: string;
|
|
18
|
+
kind: string;
|
|
19
|
+
} | null;
|
|
20
|
+
sortCode: string | null;
|
|
21
|
+
problems: string[];
|
|
22
|
+
warnings: string[];
|
|
23
|
+
advice: string[];
|
|
24
|
+
}
|
|
25
|
+
/** ISO 7064 mod 97-10 over the rearranged IBAN, with letters as 10..35. */
|
|
26
|
+
export declare function mod97(iban: string): number;
|
|
27
|
+
export declare function checkIban(input: string, supplierCountry?: string): IbanCheck;
|
|
28
|
+
export declare function ibanCheck(ctx: Ctx, input: string, opts?: {
|
|
29
|
+
country?: string;
|
|
30
|
+
}): Promise<ModuleResult<IbanCheck>>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** IBAN length per country (SWIFT IBAN registry). */
|
|
2
|
+
const LENGTHS = {
|
|
3
|
+
AD: [24, 'Andorra'], AE: [23, 'United Arab Emirates'], AL: [28, 'Albania'], AT: [20, 'Austria'], AZ: [28, 'Azerbaijan'], BA: [20, 'Bosnia and Herzegovina'],
|
|
4
|
+
BE: [16, 'Belgium'], BG: [22, 'Bulgaria'], BH: [22, 'Bahrain'], BR: [29, 'Brazil'], BY: [28, 'Belarus'], CH: [21, 'Switzerland'], CR: [22, 'Costa Rica'],
|
|
5
|
+
CY: [28, 'Cyprus'], CZ: [24, 'Czechia'], DE: [22, 'Germany'], DK: [18, 'Denmark'], DO: [28, 'Dominican Republic'], EE: [20, 'Estonia'], EG: [29, 'Egypt'],
|
|
6
|
+
ES: [24, 'Spain'], FI: [18, 'Finland'], FO: [18, 'Faroe Islands'], FR: [27, 'France'], GB: [22, 'United Kingdom'], GE: [22, 'Georgia'], GI: [23, 'Gibraltar'],
|
|
7
|
+
GL: [18, 'Greenland'], GR: [27, 'Greece'], GT: [28, 'Guatemala'], HR: [21, 'Croatia'], HU: [28, 'Hungary'], IE: [22, 'Ireland'], IL: [23, 'Israel'],
|
|
8
|
+
IQ: [23, 'Iraq'], IS: [26, 'Iceland'], IT: [27, 'Italy'], JO: [30, 'Jordan'], KW: [30, 'Kuwait'], KZ: [20, 'Kazakhstan'], LB: [28, 'Lebanon'],
|
|
9
|
+
LC: [32, 'Saint Lucia'], LI: [21, 'Liechtenstein'], LT: [20, 'Lithuania'], LU: [20, 'Luxembourg'], LV: [21, 'Latvia'], LY: [25, 'Libya'], MC: [27, 'Monaco'],
|
|
10
|
+
MD: [24, 'Moldova'], ME: [22, 'Montenegro'], MK: [19, 'North Macedonia'], MR: [27, 'Mauritania'], MT: [31, 'Malta'], MU: [30, 'Mauritius'], NL: [18, 'Netherlands'],
|
|
11
|
+
NO: [15, 'Norway'], PK: [24, 'Pakistan'], PL: [28, 'Poland'], PS: [29, 'Palestine'], PT: [25, 'Portugal'], QA: [29, 'Qatar'], RO: [24, 'Romania'],
|
|
12
|
+
RS: [22, 'Serbia'], RU: [33, 'Russia'], SA: [24, 'Saudi Arabia'], SC: [31, 'Seychelles'], SD: [18, 'Sudan'], SE: [24, 'Sweden'], SI: [19, 'Slovenia'],
|
|
13
|
+
SK: [24, 'Slovakia'], SM: [27, 'San Marino'], ST: [25, 'Sao Tome and Principe'], SV: [28, 'El Salvador'], TL: [23, 'Timor-Leste'], TN: [24, 'Tunisia'],
|
|
14
|
+
TR: [26, 'Turkey'], UA: [29, 'Ukraine'], VA: [22, 'Vatican City'], VG: [24, 'British Virgin Islands'], XK: [20, 'Kosovo'],
|
|
15
|
+
};
|
|
16
|
+
/** Where the bank identifier sits in the BBAN (start, length), for countries where it is well defined. */
|
|
17
|
+
const BANK = {
|
|
18
|
+
DE: [0, 8, 'Bankleitzahl'], AT: [0, 5, 'bank code'], CH: [0, 5, 'clearing number'], NL: [0, 4, 'bank code'], BE: [0, 3, 'bank code'], FR: [0, 5, 'bank code'],
|
|
19
|
+
ES: [0, 4, 'bank code'], IT: [1, 5, 'ABI code'], GB: [0, 4, 'bank code'], IE: [0, 4, 'bank code'], PL: [0, 8, 'bank and branch code'], SE: [0, 3, 'bank code'],
|
|
20
|
+
DK: [0, 4, 'bank code'], FI: [0, 3, 'bank code'], NO: [0, 4, 'bank code'], PT: [0, 4, 'bank code'], LU: [0, 3, 'bank code'], CZ: [0, 4, 'bank code'],
|
|
21
|
+
};
|
|
22
|
+
/** ISO 7064 mod 97-10 over the rearranged IBAN, with letters as 10..35. */
|
|
23
|
+
export function mod97(iban) {
|
|
24
|
+
const s = (iban.slice(4) + iban.slice(0, 4)).toUpperCase().replace(/[A-Z]/g, (c) => String(c.charCodeAt(0) - 55));
|
|
25
|
+
let r = 0;
|
|
26
|
+
for (let i = 0; i < s.length; i += 7)
|
|
27
|
+
r = Number(String(r) + s.slice(i, i + 7)) % 97;
|
|
28
|
+
return r;
|
|
29
|
+
}
|
|
30
|
+
export function checkIban(input, supplierCountry) {
|
|
31
|
+
const iban = input.replace(/^iban[:\s]*/i, '').replace(/[\s-]/g, '').toUpperCase();
|
|
32
|
+
const problems = [], warnings = [];
|
|
33
|
+
const out = { input, iban: iban || null, formatted: null, valid: false, country: null, countryName: null, checkDigits: null, bank: null, sortCode: null, problems, warnings, advice: [] };
|
|
34
|
+
if (!/^[A-Z]{2}[0-9]{2}[A-Z0-9]{8,30}$/.test(iban)) {
|
|
35
|
+
problems.push('not an IBAN: it should start with a two-letter country code and two check digits, followed by the account number');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
const cc = iban.slice(0, 2);
|
|
39
|
+
out.country = cc;
|
|
40
|
+
out.checkDigits = iban.slice(2, 4);
|
|
41
|
+
out.formatted = iban.replace(/(.{4})/g, '$1 ').trim();
|
|
42
|
+
const spec = LENGTHS[cc];
|
|
43
|
+
if (!spec)
|
|
44
|
+
problems.push(`${cc} does not issue IBANs`);
|
|
45
|
+
else {
|
|
46
|
+
out.countryName = spec[1];
|
|
47
|
+
if (iban.length !== spec[0])
|
|
48
|
+
problems.push(`${spec[1]} IBANs have ${spec[0]} characters, this one has ${iban.length}`);
|
|
49
|
+
}
|
|
50
|
+
if (mod97(iban) !== 1)
|
|
51
|
+
problems.push('the check digits do not match: a character is wrong or missing');
|
|
52
|
+
const b = BANK[cc];
|
|
53
|
+
if (b && !problems.length)
|
|
54
|
+
out.bank = { code: iban.slice(4 + b[0], 4 + b[0] + b[1]), kind: b[2] };
|
|
55
|
+
if (cc === 'GB' && !problems.length)
|
|
56
|
+
out.sortCode = iban.slice(8, 14).replace(/(\d\d)(\d\d)(\d\d)/, '$1-$2-$3');
|
|
57
|
+
out.valid = problems.length === 0;
|
|
58
|
+
}
|
|
59
|
+
const sc = supplierCountry?.trim().toUpperCase();
|
|
60
|
+
if (out.valid && sc && /^[A-Z]{2}$/.test(sc) && sc !== out.country) {
|
|
61
|
+
warnings.push(`the account is in ${out.countryName ?? out.country}, but the supplier is in ${LENGTHS[sc]?.[1] ?? sc}: a common sign of invoice fraud`);
|
|
62
|
+
}
|
|
63
|
+
out.advice = out.valid
|
|
64
|
+
? ['A valid IBAN only means the number is well formed. Before paying new bank details, call the supplier on a number you already have, not one from the email.']
|
|
65
|
+
: ['Do not pay to this number. Ask the supplier to confirm their bank details through a channel you already trust.'];
|
|
66
|
+
if (warnings.length)
|
|
67
|
+
out.advice.unshift('Treat a change of bank country as a red flag until the supplier confirms it by phone.');
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
export async function ibanCheck(ctx, input, opts = {}) {
|
|
71
|
+
if (!input?.trim())
|
|
72
|
+
throw new Error('give an IBAN, for example DE89 3704 0044 0532 0130 00');
|
|
73
|
+
const r = checkIban(input.trim(), opts.country);
|
|
74
|
+
return {
|
|
75
|
+
module: 'iban',
|
|
76
|
+
input: r.formatted ?? input.trim(),
|
|
77
|
+
generatedAt: ctx.now().toISOString(),
|
|
78
|
+
result: r,
|
|
79
|
+
signals: [],
|
|
80
|
+
provenance: [{ source: 'iban-registry', url: 'https://www.swift.com/standards/data-standards/iban-international-bank-account-number', status: 'LIVE', fetchedAt: ctx.now().toISOString(), note: 'offline check: ISO 13616 lengths and mod-97 check digits' }],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lookalike domains: the typos, swapped letters, homoglyphs, extra words and other endings a phisher would
|
|
3
|
+
* register to pass for a brand. Oculon generates the candidates offline, asks DNS which ones exist (Google DNS),
|
|
4
|
+
* and checks Certificate Transparency for any certificate naming the brand (crt.sh, CertSpotter as fallback):
|
|
5
|
+
* a fresh certificate on a lookalike usually means a phishing site is about to go live.
|
|
6
|
+
*/
|
|
7
|
+
import type { Ctx } from '../core/context.js';
|
|
8
|
+
import type { ModuleResult } from '../core/types.js';
|
|
9
|
+
export interface Lookalike {
|
|
10
|
+
domain: string;
|
|
11
|
+
kind: string;
|
|
12
|
+
ips: string[];
|
|
13
|
+
mx: boolean;
|
|
14
|
+
certSeen: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface CertHit {
|
|
17
|
+
name: string;
|
|
18
|
+
firstSeen: string;
|
|
19
|
+
issuer: string;
|
|
20
|
+
}
|
|
21
|
+
export interface LookalikeReport {
|
|
22
|
+
domain: string;
|
|
23
|
+
checked: number;
|
|
24
|
+
live: Lookalike[];
|
|
25
|
+
certs: CertHit[];
|
|
26
|
+
risk: 'high' | 'medium' | 'low';
|
|
27
|
+
note: string;
|
|
28
|
+
}
|
|
29
|
+
/** Candidate lookalikes for a domain, labelled by how they were made. Deterministic and capped. */
|
|
30
|
+
export declare function candidates(domain: string, max?: number): {
|
|
31
|
+
domain: string;
|
|
32
|
+
kind: string;
|
|
33
|
+
}[];
|
|
34
|
+
export declare function lookalikes(ctx: Ctx, input: string): Promise<ModuleResult<LookalikeReport>>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { signalId } from '../core/text.js';
|
|
2
|
+
import { certspotter } from '../sources/certs.js';
|
|
3
|
+
const KEYS = { q: 'wa', w: 'qes', e: 'wrd', r: 'etf', t: 'ryg', y: 'tuh', u: 'yij', i: 'uok', o: 'ipl', p: 'ol', a: 'qsz', s: 'adw', d: 'sfe', f: 'dgr', g: 'fht', h: 'gjy', j: 'hku', k: 'jli', l: 'kp', z: 'ax', x: 'zc', c: 'xv', v: 'cb', b: 'vn', n: 'bm', m: 'n' };
|
|
4
|
+
const GLYPHS = [['o', '0'], ['l', '1'], ['i', '1'], ['i', 'l'], ['l', 'i'], ['e', '3'], ['a', '4'], ['s', '5'], ['m', 'rn'], ['rn', 'm'], ['w', 'vv'], ['vv', 'w'], ['d', 'cl'], ['g', 'q'], ['u', 'v']];
|
|
5
|
+
const WORDS = ['login', 'secure', 'support', 'verify', 'account', 'app', 'help', 'official', 'wallet', 'claim', 'airdrop', 'pay', 'billing'];
|
|
6
|
+
const TLDS = ['com', 'net', 'org', 'io', 'co', 'app', 'live', 'xyz', 'top', 'site', 'online', 'info', 'shop', 'click', 'link', 'vip', 'pro'];
|
|
7
|
+
/** Candidate lookalikes for a domain, labelled by how they were made. Deterministic and capped. */
|
|
8
|
+
export function candidates(domain, max = 160) {
|
|
9
|
+
const d = domain.toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/.*$/, '');
|
|
10
|
+
const dot = d.indexOf('.');
|
|
11
|
+
if (dot < 1)
|
|
12
|
+
throw new Error(`not a domain: ${domain}`);
|
|
13
|
+
const name = d.slice(0, dot), tld = d.slice(dot + 1);
|
|
14
|
+
const out = new Map();
|
|
15
|
+
const put = (n, t, kind) => { const c = `${n}.${t}`; if (n && c !== d && /^[a-z0-9-]+$/.test(n) && !n.startsWith('-') && !n.endsWith('-') && !out.has(c))
|
|
16
|
+
out.set(c, kind); };
|
|
17
|
+
for (const t of TLDS)
|
|
18
|
+
if (t !== tld)
|
|
19
|
+
put(name, t, 'other ending');
|
|
20
|
+
for (let i = 0; i < name.length; i++) {
|
|
21
|
+
put(name.slice(0, i) + name.slice(i + 1), tld, 'missing letter');
|
|
22
|
+
put(name.slice(0, i) + name[i] + name.slice(i), tld, 'double letter');
|
|
23
|
+
if (i < name.length - 1)
|
|
24
|
+
put(name.slice(0, i) + name[i + 1] + name[i] + name.slice(i + 2), tld, 'swapped letters');
|
|
25
|
+
for (const k of KEYS[name[i]] ?? '')
|
|
26
|
+
put(name.slice(0, i) + k + name.slice(i + 1), tld, 'keyboard typo');
|
|
27
|
+
if (i > 0)
|
|
28
|
+
put(`${name.slice(0, i)}-${name.slice(i)}`, tld, 'hyphen');
|
|
29
|
+
}
|
|
30
|
+
for (const [a, b] of GLYPHS) {
|
|
31
|
+
let at = name.indexOf(a);
|
|
32
|
+
while (at >= 0) {
|
|
33
|
+
put(name.slice(0, at) + b + name.slice(at + a.length), tld, 'lookalike characters');
|
|
34
|
+
at = name.indexOf(a, at + 1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const w of WORDS) {
|
|
38
|
+
put(`${name}-${w}`, tld, 'brand plus word');
|
|
39
|
+
put(`${w}-${name}`, tld, 'brand plus word');
|
|
40
|
+
put(`${name}${w}`, 'com', 'brand plus word');
|
|
41
|
+
}
|
|
42
|
+
// Endings and words first: they are what phishing kits register most often.
|
|
43
|
+
const order = ['brand plus word', 'other ending', 'lookalike characters', 'missing letter', 'swapped letters', 'double letter', 'hyphen', 'keyboard typo'];
|
|
44
|
+
return [...out].map(([domain, kind]) => ({ domain, kind })).sort((a, b) => order.indexOf(a.kind) - order.indexOf(b.kind)).slice(0, max);
|
|
45
|
+
}
|
|
46
|
+
async function resolve(ctx, name, type) {
|
|
47
|
+
return ctx.http.get(`https://dns.google/resolve?name=${encodeURIComponent(name)}&type=${type}`, { source: 'google-dns', ttlSec: 12 * 3600, retries: 1, keep: (x) => ({ Status: x.Status, Answer: (x.Answer ?? []).map((a) => ({ type: a.type, data: a.data })) }) });
|
|
48
|
+
}
|
|
49
|
+
/** Certificates whose names contain the brand anywhere (crt.sh full-text match), unexpired only. */
|
|
50
|
+
async function crtBrand(ctx, brand) {
|
|
51
|
+
const url = `https://crt.sh/?q=${encodeURIComponent(`%${brand}%`)}&output=json&exclude=expired`;
|
|
52
|
+
const r = await ctx.http.get(url, { source: 'crt.sh', ttlSec: 6 * 3600, timeoutMs: 60_000, retries: 1, keep: (rows) => (Array.isArray(rows) ? rows.slice(0, 3000).map((x) => ({ name_value: x.name_value, not_before: x.not_before, issuer_name: x.issuer_name })) : rows) });
|
|
53
|
+
const data = Array.isArray(r.data)
|
|
54
|
+
? r.data.map((row) => ({ names: row.name_value.split(/\s+/).filter(Boolean), notBefore: row.not_before.endsWith('Z') ? row.not_before : `${row.not_before}Z`, issuer: /O=([^,]+)/.exec(row.issuer_name)?.[1]?.replace(/"/g, '') ?? row.issuer_name }))
|
|
55
|
+
: null;
|
|
56
|
+
return { data, prov: r.prov };
|
|
57
|
+
}
|
|
58
|
+
async function pool(items, n, fn) {
|
|
59
|
+
const out = new Array(items.length);
|
|
60
|
+
let i = 0;
|
|
61
|
+
await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => { while (i < items.length) {
|
|
62
|
+
const k = i++;
|
|
63
|
+
out[k] = await fn(items[k]);
|
|
64
|
+
} }));
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
export async function lookalikes(ctx, input) {
|
|
68
|
+
const domain = input.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').replace(/\/.*$/, '');
|
|
69
|
+
const cands = candidates(domain);
|
|
70
|
+
const name = domain.split('.')[0];
|
|
71
|
+
const provenance = [];
|
|
72
|
+
let failed = 0;
|
|
73
|
+
const found = await pool(cands, 8, async (c) => {
|
|
74
|
+
const a = await resolve(ctx, c.domain, 'A');
|
|
75
|
+
if (!a.data) {
|
|
76
|
+
failed++;
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const ips = (a.data.Answer ?? []).filter((x) => x.type === 1).map((x) => x.data);
|
|
80
|
+
if (!ips.length)
|
|
81
|
+
return null;
|
|
82
|
+
const mx = await resolve(ctx, c.domain, 'MX');
|
|
83
|
+
return { ...c, ips, mx: (mx.data?.Answer ?? []).some((x) => x.type === 15 && !/^0 \.$/.test(x.data)), certSeen: null };
|
|
84
|
+
});
|
|
85
|
+
provenance.push({ source: 'google-dns', url: 'https://dns.google/resolve', status: failed === cands.length ? 'ERROR' : 'LIVE', fetchedAt: ctx.now().toISOString(), note: `${cands.length} candidates resolved${failed ? `, ${failed} lookups failed` : ''}` });
|
|
86
|
+
// Certificates naming the brand anywhere, from the last 90 days, excluding the brand's own domain.
|
|
87
|
+
let ct = await crtBrand(ctx, name.length >= 4 ? name : domain);
|
|
88
|
+
if (!ct.data) {
|
|
89
|
+
const alt = await certspotter(ctx, domain);
|
|
90
|
+
provenance.push(ct.prov);
|
|
91
|
+
ct = alt;
|
|
92
|
+
}
|
|
93
|
+
provenance.push(ct.prov);
|
|
94
|
+
const since = ctx.now().getTime() - 90 * 86_400_000;
|
|
95
|
+
const certMap = new Map();
|
|
96
|
+
for (const e of (ct.data ?? [])) {
|
|
97
|
+
if (new Date(e.notBefore).getTime() < since)
|
|
98
|
+
continue;
|
|
99
|
+
for (const n of e.names) {
|
|
100
|
+
const host = n.replace(/^\*\./, '').toLowerCase();
|
|
101
|
+
if (!host.includes(name) || host === domain || host.endsWith(`.${domain}`))
|
|
102
|
+
continue;
|
|
103
|
+
const prev = certMap.get(host);
|
|
104
|
+
if (!prev || e.notBefore < prev.firstSeen)
|
|
105
|
+
certMap.set(host, { name: host, firstSeen: e.notBefore, issuer: e.issuer });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const certs = [...certMap.values()].sort((a, b) => b.firstSeen.localeCompare(a.firstSeen)).slice(0, 40);
|
|
109
|
+
const live = found.filter((x) => !!x).map((l) => ({ ...l, certSeen: certMap.get(l.domain)?.firstSeen ?? null }));
|
|
110
|
+
const fresh = certs.filter((c) => ctx.now().getTime() - new Date(c.firstSeen).getTime() < 14 * 86_400_000);
|
|
111
|
+
const risk = fresh.length || live.some((l) => l.mx && l.kind !== 'other ending') ? 'high' : live.length || certs.length ? 'medium' : 'low';
|
|
112
|
+
const nowIso = ctx.now().toISOString();
|
|
113
|
+
const signals = fresh.length ? [{
|
|
114
|
+
id: signalId('lookalike', domain, fresh.slice(0, 5).map((c) => c.name).join(',')), module: 'lookalike', title: `${fresh.length} new certificate${fresh.length === 1 ? '' : 's'} for lookalikes of ${domain}`, score: 62, entity: domain,
|
|
115
|
+
evidence: fresh.slice(0, 3).map((c) => ({ source: 'crt.sh', text: `${c.name} · certificate from ${c.issuer}, ${c.firstSeen.slice(0, 10)}`, url: `https://crt.sh/?q=${encodeURIComponent(c.name)}` })), createdAt: nowIso,
|
|
116
|
+
}] : [];
|
|
117
|
+
return {
|
|
118
|
+
module: 'lookalike', input: domain, generatedAt: nowIso,
|
|
119
|
+
result: { domain, checked: cands.length, live, certs, risk, note: 'A lookalike that resolves is not proof of phishing: some are parked, owned by the brand, or unrelated. Fresh certificates and mail servers on a lookalike are the strongest signs.' },
|
|
120
|
+
signals, provenance,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -25,7 +25,7 @@ export interface Delivery {
|
|
|
25
25
|
export declare const isOwner: (o: string) => boolean;
|
|
26
26
|
export declare function listPersonal(ctx: Ctx, owner: string): PersonalMonitor[];
|
|
27
27
|
/** Reads the request into a rule and saves it for this owner (at most MAX_PER_OWNER). */
|
|
28
|
-
export declare function addPersonal(ctx: Ctx, owner: string, text: string): Promise<{
|
|
28
|
+
export declare function addPersonal(ctx: Ctx, owner: string, text: string, max?: number): Promise<{
|
|
29
29
|
monitor: PersonalMonitor;
|
|
30
30
|
rule: MonitorRule;
|
|
31
31
|
method: string;
|