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.
- package/README.md +75 -5
- package/dist/cli/main.js +297 -0
- package/dist/core/evm.d.ts +20 -0
- package/dist/core/evm.js +165 -0
- package/dist/core/http.js +7 -0
- package/dist/core/quota.js +23 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +68 -0
- package/dist/mcp.js +81 -2
- package/dist/modules/address.d.ts +32 -0
- package/dist/modules/address.js +91 -0
- package/dist/modules/breach.d.ts +53 -0
- package/dist/modules/breach.js +98 -0
- package/dist/modules/company.d.ts +53 -0
- package/dist/modules/company.js +149 -0
- package/dist/modules/hashcheck.d.ts +29 -0
- package/dist/modules/hashcheck.js +82 -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/ipintel.d.ts +52 -0
- package/dist/modules/ipintel.js +149 -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/phone.d.ts +32 -0
- package/dist/modules/phone.js +148 -0
- package/dist/modules/ransomware.d.ts +56 -0
- package/dist/modules/ransomware.js +85 -0
- package/dist/modules/satellites.d.ts +45 -0
- package/dist/modules/satellites.js +113 -0
- package/dist/modules/utility.d.ts +121 -0
- package/dist/modules/utility.js +306 -0
- package/dist/sources/threatintel.d.ts +151 -0
- package/dist/sources/threatintel.js +256 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +93 -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/index.html +70 -3
- package/dist/web/insights.js +2 -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 +11 -0
- package/dist/web/public.js +13 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +161 -4
- package/dist/web/token.html +97 -0
- package/dist/web/token.json +9 -0
- package/dist/web/utility.html +225 -0
- package/package.json +2 -2
|
@@ -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,52 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { ModuleResult } from '../core/types.js';
|
|
3
|
+
import { type AbuseIpDb, type GreyNoise, type InternetDb, type OtxPulses, type ThreatFoxHit, type VtStats } from '../sources/threatintel.js';
|
|
4
|
+
export type IpVerdict = 'malicious' | 'suspicious' | 'no known abuse';
|
|
5
|
+
export interface IpCheck {
|
|
6
|
+
ip: string;
|
|
7
|
+
resolvedFrom: string | null;
|
|
8
|
+
verdict: IpVerdict;
|
|
9
|
+
risk: number;
|
|
10
|
+
reasons: string[];
|
|
11
|
+
location: {
|
|
12
|
+
country: string | null;
|
|
13
|
+
countryCode: string | null;
|
|
14
|
+
region: string | null;
|
|
15
|
+
city: string | null;
|
|
16
|
+
} | null;
|
|
17
|
+
network: {
|
|
18
|
+
asn: string | null;
|
|
19
|
+
name: string | null;
|
|
20
|
+
isp: string | null;
|
|
21
|
+
domain: string | null;
|
|
22
|
+
type: string | null;
|
|
23
|
+
reverse: string | null;
|
|
24
|
+
};
|
|
25
|
+
flags: {
|
|
26
|
+
tor: boolean;
|
|
27
|
+
proxy: boolean;
|
|
28
|
+
hosting: boolean;
|
|
29
|
+
mobile: boolean;
|
|
30
|
+
scanner: boolean;
|
|
31
|
+
knownGood: boolean;
|
|
32
|
+
};
|
|
33
|
+
abuseipdb: AbuseIpDb | null;
|
|
34
|
+
greynoise: GreyNoise | null;
|
|
35
|
+
otx: OtxPulses | null;
|
|
36
|
+
virustotal: VtStats | null;
|
|
37
|
+
threatfox: ThreatFoxHit[];
|
|
38
|
+
drop: {
|
|
39
|
+
listed: boolean;
|
|
40
|
+
entry: string | null;
|
|
41
|
+
asnListed: boolean;
|
|
42
|
+
};
|
|
43
|
+
ports: InternetDb | null;
|
|
44
|
+
advice: string[];
|
|
45
|
+
}
|
|
46
|
+
/** Plain-language reasons and a 0-100 risk from the source answers. */
|
|
47
|
+
export declare function scoreIp(x: Pick<IpCheck, 'abuseipdb' | 'greynoise' | 'otx' | 'virustotal' | 'threatfox' | 'drop' | 'flags'>): {
|
|
48
|
+
risk: number;
|
|
49
|
+
verdict: IpVerdict;
|
|
50
|
+
reasons: string[];
|
|
51
|
+
};
|
|
52
|
+
export declare function ipCheck(ctx: Ctx, input: string): Promise<ModuleResult<IpCheck>>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IP check: who runs this address, and is it known for abuse?
|
|
3
|
+
* Location and network (ip-api.com, IPinfo Lite, PeeringDB), abuse reports (AbuseIPDB), internet scanning
|
|
4
|
+
* (GreyNoise), threat reports (AlienVault OTX), antivirus verdicts (VirusTotal), malware infrastructure
|
|
5
|
+
* (ThreatFox), hijacked or criminal networks (Spamhaus DROP), Tor exits and open ports (Shodan InternetDB).
|
|
6
|
+
* A domain is resolved to its first address first.
|
|
7
|
+
*/
|
|
8
|
+
import { isIP } from 'node:net';
|
|
9
|
+
import { clamp } from '../core/stats.js';
|
|
10
|
+
import { abuseIpDb, greyNoise, inCidr, internetDb, ipApi, ipInfo, isPublicIp, otx, peeringDb, spamhausDrop, threatFox, torExits, virusTotal, } from '../sources/threatintel.js';
|
|
11
|
+
async function resolve(ctx, host) {
|
|
12
|
+
for (const type of ['A', 'AAAA']) {
|
|
13
|
+
const r = await ctx.http.get(`https://dns.google/resolve?name=${encodeURIComponent(host)}&type=${type}`, { source: 'google-dns', ttlSec: 1800 });
|
|
14
|
+
const ip = (r.data?.Answer ?? []).find((a) => a.type === (type === 'A' ? 1 : 28))?.data;
|
|
15
|
+
if (ip)
|
|
16
|
+
return { ip, prov: r.prov };
|
|
17
|
+
if (type === 'AAAA')
|
|
18
|
+
return { ip: null, prov: r.prov };
|
|
19
|
+
}
|
|
20
|
+
return { ip: null, prov: { source: 'google-dns', url: '', status: 'ERROR', fetchedAt: new Date().toISOString() } };
|
|
21
|
+
}
|
|
22
|
+
/** Plain-language reasons and a 0-100 risk from the source answers. */
|
|
23
|
+
export function scoreIp(x) {
|
|
24
|
+
const reasons = [];
|
|
25
|
+
let risk = 0;
|
|
26
|
+
if (x.drop.listed) {
|
|
27
|
+
risk = Math.max(risk, 95);
|
|
28
|
+
reasons.push(`on the Spamhaus DROP list (${x.drop.entry}): a network run by or hijacked for criminals`);
|
|
29
|
+
}
|
|
30
|
+
if (x.drop.asnListed) {
|
|
31
|
+
risk = Math.max(risk, 85);
|
|
32
|
+
reasons.push('its network (ASN) is on the Spamhaus ASN-DROP list');
|
|
33
|
+
}
|
|
34
|
+
if (x.threatfox.length) {
|
|
35
|
+
risk = Math.max(risk, 85);
|
|
36
|
+
reasons.push(`ThreatFox lists it as malware infrastructure${x.threatfox[0].malware ? ` (${x.threatfox[0].malware})` : ''}`);
|
|
37
|
+
}
|
|
38
|
+
const a = x.abuseipdb;
|
|
39
|
+
if (a && a.reports > 0) {
|
|
40
|
+
risk = Math.max(risk, a.score >= 75 ? 85 : a.score >= 25 ? 55 : a.score > 0 ? 25 : 10);
|
|
41
|
+
reasons.push(`${a.reports} abuse report${a.reports === 1 ? '' : 's'} from ${a.reporters} reporter${a.reporters === 1 ? '' : 's'} in 90 days (AbuseIPDB confidence ${a.score}%)`);
|
|
42
|
+
}
|
|
43
|
+
const g = x.greynoise;
|
|
44
|
+
if (g?.noise) {
|
|
45
|
+
risk = Math.max(risk, g.classification === 'malicious' ? 70 : 30);
|
|
46
|
+
reasons.push(`GreyNoise sees it scanning the internet${g.classification ? `, classified ${g.classification}` : ''}${g.name ? ` (${g.name})` : ''}`);
|
|
47
|
+
}
|
|
48
|
+
const v = x.virustotal;
|
|
49
|
+
if (v && v.malicious > 0) {
|
|
50
|
+
risk = Math.max(risk, v.malicious >= 8 ? 80 : v.malicious >= 3 ? 50 : 15);
|
|
51
|
+
reasons.push(`${v.malicious} of ${v.engines} VirusTotal engines flag it`);
|
|
52
|
+
}
|
|
53
|
+
const o = x.otx;
|
|
54
|
+
if (o && o.count > 0 && !o.whitelisted) {
|
|
55
|
+
risk = Math.max(risk, o.count >= 10 ? 45 : 20);
|
|
56
|
+
reasons.push(`mentioned in ${o.count} AlienVault OTX threat report${o.count === 1 ? '' : 's'}`);
|
|
57
|
+
}
|
|
58
|
+
if (x.flags.tor) {
|
|
59
|
+
risk = Math.max(risk, 40);
|
|
60
|
+
reasons.push('a Tor exit node: traffic from it can come from anyone');
|
|
61
|
+
}
|
|
62
|
+
if (x.flags.proxy && !x.flags.knownGood)
|
|
63
|
+
reasons.push('a known proxy or VPN address');
|
|
64
|
+
// Big shared services (Google DNS, Cloudflare) collect stray reports; say so instead of alarming.
|
|
65
|
+
if (x.flags.knownGood) {
|
|
66
|
+
risk = Math.min(risk, 20);
|
|
67
|
+
reasons.push('a known benign service (allow-listed by AbuseIPDB, GreyNoise or OTX)');
|
|
68
|
+
}
|
|
69
|
+
risk = clamp(Math.round(risk), 0, 100);
|
|
70
|
+
return { risk, verdict: risk >= 70 ? 'malicious' : risk >= 35 ? 'suspicious' : 'no known abuse', reasons };
|
|
71
|
+
}
|
|
72
|
+
export async function ipCheck(ctx, input) {
|
|
73
|
+
const raw = input.trim().replace(/^\[|\]$/g, '');
|
|
74
|
+
if (!raw)
|
|
75
|
+
throw new Error('missing IP address or domain');
|
|
76
|
+
const provenance = [];
|
|
77
|
+
let ip = raw;
|
|
78
|
+
let resolvedFrom = null;
|
|
79
|
+
if (!isIP(raw)) {
|
|
80
|
+
const host = raw.toLowerCase().replace(/^https?:\/\//, '').replace(/[/:?#].*$/, '');
|
|
81
|
+
if (!/^[a-z0-9.-]+\.[a-z]{2,}$/.test(host))
|
|
82
|
+
throw new Error(`not an IP address or domain: ${input}`);
|
|
83
|
+
const r = await resolve(ctx, host);
|
|
84
|
+
provenance.push(r.prov);
|
|
85
|
+
if (!r.ip)
|
|
86
|
+
throw new Error(`domain not found: ${host} has no IP address`);
|
|
87
|
+
ip = r.ip;
|
|
88
|
+
resolvedFrom = host;
|
|
89
|
+
}
|
|
90
|
+
if (!isPublicIp(ip))
|
|
91
|
+
throw new Error(`not a public IP address: ${ip} is private, reserved or local`);
|
|
92
|
+
const v6 = isIP(ip) === 6;
|
|
93
|
+
const [loc, info, abuse, gn, ox, vt, tf, tor, drop, ports] = await Promise.all([
|
|
94
|
+
ipApi(ctx, ip), ipInfo(ctx, ip), abuseIpDb(ctx, ip), greyNoise(ctx, ip), otx(ctx, v6 ? 'IPv6' : 'IPv4', ip), virusTotal(ctx, 'ip', ip), threatFox(ctx, 'ioc', ip), torExits(ctx), spamhausDrop(ctx), internetDb(ctx, ip),
|
|
95
|
+
]);
|
|
96
|
+
provenance.push(loc.prov, info.prov, abuse.prov, gn.prov, ox.prov, vt.prov, tf.prov, tor.prov, ...drop.prov, ports.prov);
|
|
97
|
+
const asnNum = Number((info.data?.asn ?? loc.data?.as ?? '').replace(/^AS/i, '').split(/\s/)[0]);
|
|
98
|
+
let pdb = null;
|
|
99
|
+
if (Number.isInteger(asnNum) && asnNum > 0) {
|
|
100
|
+
const p = await peeringDb(ctx, asnNum);
|
|
101
|
+
provenance.push(p.prov);
|
|
102
|
+
pdb = p.data;
|
|
103
|
+
}
|
|
104
|
+
const dropEntry = drop.data?.cidrs.find((c) => inCidr(ip, c.cidr)) ?? null;
|
|
105
|
+
const loc2 = loc.data;
|
|
106
|
+
const flags = {
|
|
107
|
+
tor: Boolean(tor.data?.has(ip) || abuse.data?.isTor),
|
|
108
|
+
proxy: Boolean(loc2?.proxy),
|
|
109
|
+
hosting: Boolean(loc2?.hosting),
|
|
110
|
+
mobile: Boolean(loc2?.mobile),
|
|
111
|
+
scanner: Boolean(gn.data?.noise),
|
|
112
|
+
knownGood: Boolean(abuse.data?.whitelisted || gn.data?.riot || ox.data?.whitelisted),
|
|
113
|
+
};
|
|
114
|
+
const part = {
|
|
115
|
+
abuseipdb: abuse.data, greynoise: gn.data, otx: ox.data, virustotal: vt.data, threatfox: tf.data ?? [], flags,
|
|
116
|
+
drop: { listed: Boolean(dropEntry), entry: dropEntry ? `${dropEntry.cidr}${dropEntry.id ? ` ${dropEntry.id}` : ''}` : null, asnListed: Boolean(asnNum && drop.data?.asns.some((x) => x.asn === asnNum)) },
|
|
117
|
+
};
|
|
118
|
+
const { risk, verdict, reasons } = scoreIp(part);
|
|
119
|
+
const advice = [];
|
|
120
|
+
if (verdict === 'malicious')
|
|
121
|
+
advice.push('Block this address at your firewall or mail server, and check your logs for earlier connections from it.');
|
|
122
|
+
else if (verdict === 'suspicious')
|
|
123
|
+
advice.push('Treat connections from this address with care: rate limit it, and watch for login attempts or scans.');
|
|
124
|
+
else
|
|
125
|
+
advice.push('No source reports abuse from this address. That is not a guarantee: new addresses have no history yet.');
|
|
126
|
+
if (flags.tor)
|
|
127
|
+
advice.push('Tor exits are shared by many users; blocking one blocks all of them, not just the bad actor.');
|
|
128
|
+
if (ports.data?.vulns.length)
|
|
129
|
+
advice.push(`Shodan lists ${ports.data.vulns.length} known vulnerabilit${ports.data.vulns.length === 1 ? 'y' : 'ies'} on its open ports; if this is your server, patch it.`);
|
|
130
|
+
return {
|
|
131
|
+
module: 'ipcheck',
|
|
132
|
+
input: resolvedFrom ?? ip,
|
|
133
|
+
generatedAt: ctx.now().toISOString(),
|
|
134
|
+
result: {
|
|
135
|
+
ip,
|
|
136
|
+
resolvedFrom,
|
|
137
|
+
verdict,
|
|
138
|
+
risk,
|
|
139
|
+
reasons,
|
|
140
|
+
location: loc2 ? { country: loc2.country, countryCode: loc2.countryCode, region: loc2.region, city: loc2.city } : info.data ? { country: info.data.country, countryCode: info.data.countryCode, region: null, city: null } : null,
|
|
141
|
+
network: { asn: info.data?.asn ?? (loc2?.as?.split(' ')[0] ?? null), name: info.data?.asName ?? pdb?.name ?? loc2?.org ?? null, isp: loc2?.isp ?? abuse.data?.isp ?? null, domain: info.data?.asDomain ?? abuse.data?.domain ?? null, type: pdb?.type ?? abuse.data?.usageType ?? null, reverse: loc2?.reverse ?? null },
|
|
142
|
+
...part,
|
|
143
|
+
ports: ports.data,
|
|
144
|
+
advice,
|
|
145
|
+
},
|
|
146
|
+
signals: [],
|
|
147
|
+
provenance,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
@@ -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;
|
package/dist/modules/personal.js
CHANGED
|
@@ -28,13 +28,13 @@ export function listPersonal(ctx, owner) {
|
|
|
28
28
|
return db(ctx).prepare('SELECT * FROM personal_monitors WHERE owner = ? ORDER BY id').all(owner).map(toMonitor);
|
|
29
29
|
}
|
|
30
30
|
/** Reads the request into a rule and saves it for this owner (at most MAX_PER_OWNER). */
|
|
31
|
-
export async function addPersonal(ctx, owner, text) {
|
|
31
|
+
export async function addPersonal(ctx, owner, text, max = MAX_PER_OWNER) {
|
|
32
32
|
if (!isOwner(owner))
|
|
33
33
|
throw new Error('invalid owner');
|
|
34
34
|
const d = db(ctx);
|
|
35
35
|
const n = d.prepare('SELECT COUNT(*) n FROM personal_monitors WHERE owner = ?').get(owner).n;
|
|
36
|
-
if (n >=
|
|
37
|
-
throw new Error(`you can keep up to ${
|
|
36
|
+
if (n >= max)
|
|
37
|
+
throw new Error(`you can keep up to ${max} monitors; remove one first${max === MAX_PER_OWNER ? ' (OCULON holders can keep more)' : ''}`);
|
|
38
38
|
const r = await parseMonitor(text);
|
|
39
39
|
d.prepare('INSERT INTO personal_monitors (owner, kind, target, description, created_at) VALUES (?, ?, ?, ?, ?) ON CONFLICT(owner, kind, target) DO NOTHING').run(owner, r.kind, r.target, r.description, ctx.now().getTime());
|
|
40
40
|
const row = d.prepare('SELECT * FROM personal_monitors WHERE owner = ? AND kind = ? AND target = ?').get(owner, r.kind, r.target);
|
|
@@ -54,7 +54,17 @@ export function personalAlerts(ctx, owner, limit = 50) {
|
|
|
54
54
|
export async function runPersonal(ctx, opts = {}) {
|
|
55
55
|
const d = db(ctx);
|
|
56
56
|
const now = ctx.now().getTime();
|
|
57
|
-
|
|
57
|
+
// Monitors of OCULON holders (a signed-in wallet with enough tokens) are checked every ~15 minutes instead of hourly.
|
|
58
|
+
let holderSql = '';
|
|
59
|
+
try {
|
|
60
|
+
d.prepare('SELECT 1 FROM holder_sessions LIMIT 1').get();
|
|
61
|
+
holderSql = ' OR (last_run <= ? AND owner IN (SELECT owner FROM holder_sessions WHERE expires_at > ?))';
|
|
62
|
+
}
|
|
63
|
+
catch { /* no holder table yet */ }
|
|
64
|
+
const args = [now - (opts.everyMs ?? 55 * 60_000)];
|
|
65
|
+
if (holderSql)
|
|
66
|
+
args.push(now - 14 * 60_000, now);
|
|
67
|
+
const rows = d.prepare(`SELECT * FROM personal_monitors WHERE last_run IS NULL OR last_run <= ?${holderSql} ORDER BY COALESCE(last_run, 0) LIMIT ?`).all(...args, opts.max ?? 60);
|
|
58
68
|
const out = [];
|
|
59
69
|
for (const r of rows) {
|
|
60
70
|
const item = { id: r.id, kind: r.kind, target: r.target, label: r.description, createdAt: new Date(r.created_at).toISOString(), lastRun: r.last_run ? new Date(r.last_run).toISOString() : null };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phone number check, for the sender of a suspicious SMS or a missed call from abroad.
|
|
3
|
+
* Offline: country from the calling code, number length, premium-rate and "one ring" callback-scam codes.
|
|
4
|
+
* Online (NUMVERIFY_API_KEY, free 100 lookups a month): validity, carrier, line type (mobile, landline, VoIP)
|
|
5
|
+
* and location. Owner names are never looked up.
|
|
6
|
+
*/
|
|
7
|
+
import type { Ctx } from '../core/context.js';
|
|
8
|
+
import type { ModuleResult } from '../core/types.js';
|
|
9
|
+
export interface PhoneCheck {
|
|
10
|
+
e164: string;
|
|
11
|
+
countryCode: string;
|
|
12
|
+
country: string | null;
|
|
13
|
+
iso2: string | null;
|
|
14
|
+
plausible: boolean;
|
|
15
|
+
lineType: string | null;
|
|
16
|
+
carrier: string | null;
|
|
17
|
+
location: string | null;
|
|
18
|
+
valid: boolean | null;
|
|
19
|
+
risk: 'high' | 'medium' | 'low';
|
|
20
|
+
warnings: string[];
|
|
21
|
+
advice: string[];
|
|
22
|
+
}
|
|
23
|
+
/** Normalise to E.164 digits. A national number needs a default country (ISO code). */
|
|
24
|
+
export declare function toE164(input: string, defaultCountry?: string): {
|
|
25
|
+
digits: string;
|
|
26
|
+
code: string;
|
|
27
|
+
} | null;
|
|
28
|
+
/** What can be told without any lookup. */
|
|
29
|
+
export declare function offlinePhone(digits: string, code: string): Pick<PhoneCheck, 'country' | 'iso2' | 'plausible' | 'lineType' | 'warnings'>;
|
|
30
|
+
export declare function phoneCheck(ctx: Ctx, input: string, opts?: {
|
|
31
|
+
country?: string;
|
|
32
|
+
}): Promise<ModuleResult<PhoneCheck>>;
|