sentrion 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +134 -2
- package/bin/sentrion.js +11 -0
- package/lib/cli.js +117 -0
- package/lib/cmd-allow.js +16 -0
- package/lib/cmd-doctor.js +40 -0
- package/lib/cmd-init.js +26 -0
- package/lib/cmd-mode.js +22 -0
- package/lib/cmd-rules.js +51 -0
- package/lib/cmd-scan.js +58 -0
- package/lib/cmd-shell-init.js +28 -0
- package/lib/cmd-test.js +26 -0
- package/lib/cmd-trust.js +53 -0
- package/lib/cmd-update.js +59 -0
- package/lib/data/malware.json +56 -0
- package/lib/data/typosquats.json +13 -0
- package/lib/guard.js +246 -0
- package/lib/hook.js +257 -0
- package/lib/policy.js +109 -0
- package/lib/proxy.js +61 -0
- package/lib/py/sitecustomize.py +167 -0
- package/lib/report.js +131 -0
- package/lib/rules.js +43 -0
- package/lib/scan.js +131 -0
- package/lib/sensors.js +112 -0
- package/lib/store.js +32 -0
- package/lib/ui.js +63 -0
- package/package.json +43 -4
package/lib/sensors.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Tier-2 OS sensors (parent side): enumerate the guarded process tree and
|
|
3
|
+
// kill it. Zero dependencies — reads /proc on Linux, `ps` on macOS, PowerShell
|
|
4
|
+
// on Windows. Used as the backstop for anything the language hook can't see
|
|
5
|
+
// (native binaries, non-Node runtimes) and to kill the whole group on a block.
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const cp = require('child_process');
|
|
9
|
+
|
|
10
|
+
const isWin = process.platform === 'win32';
|
|
11
|
+
const isLinux = process.platform === 'linux';
|
|
12
|
+
|
|
13
|
+
// [{pid, ppid, comm}]
|
|
14
|
+
function listProcesses() {
|
|
15
|
+
try {
|
|
16
|
+
if (isLinux) return listLinux();
|
|
17
|
+
if (isWin) return listWin();
|
|
18
|
+
return listPs(); // macOS / other unix
|
|
19
|
+
} catch { return []; }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function listLinux() {
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const name of fs.readdirSync('/proc')) {
|
|
25
|
+
if (!/^\d+$/.test(name)) continue;
|
|
26
|
+
try {
|
|
27
|
+
const stat = fs.readFileSync(`/proc/${name}/stat`, 'utf8');
|
|
28
|
+
// comm is in parentheses and may contain spaces → split on last ')'
|
|
29
|
+
const r = stat.lastIndexOf(')');
|
|
30
|
+
const pid = Number(stat.slice(0, stat.indexOf(' ')));
|
|
31
|
+
const comm = stat.slice(stat.indexOf('(') + 1, r);
|
|
32
|
+
const rest = stat.slice(r + 2).split(' ');
|
|
33
|
+
const ppid = Number(rest[1]);
|
|
34
|
+
out.push({ pid, ppid, comm });
|
|
35
|
+
} catch {}
|
|
36
|
+
}
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function listPs() {
|
|
41
|
+
const txt = cp.execFileSync('ps', ['-axo', 'pid=,ppid=,comm='], { encoding: 'utf8', maxBuffer: 8 << 20 });
|
|
42
|
+
return txt.trim().split('\n').map((l) => {
|
|
43
|
+
const m = l.trim().match(/^(\d+)\s+(\d+)\s+(.*)$/);
|
|
44
|
+
if (!m) return null;
|
|
45
|
+
return { pid: Number(m[1]), ppid: Number(m[2]), comm: m[3].split(/[\\/]/).pop() };
|
|
46
|
+
}).filter(Boolean);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function listWin() {
|
|
50
|
+
const txt = cp.execFileSync('powershell', ['-NoProfile', '-Command',
|
|
51
|
+
'Get-CimInstance Win32_Process | Select-Object ProcessId,ParentProcessId,Name | ConvertTo-Csv -NoTypeInformation'],
|
|
52
|
+
{ encoding: 'utf8', maxBuffer: 8 << 20 });
|
|
53
|
+
return txt.trim().split('\n').slice(1).map((l) => {
|
|
54
|
+
const m = l.replace(/"/g, '').split(',');
|
|
55
|
+
if (m.length < 3) return null;
|
|
56
|
+
return { pid: Number(m[0]), ppid: Number(m[1]), comm: m[2] };
|
|
57
|
+
}).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// all descendants of root (inclusive)
|
|
61
|
+
function subtree(rootPid, procs = listProcesses()) {
|
|
62
|
+
const byParent = new Map();
|
|
63
|
+
for (const p of procs) {
|
|
64
|
+
if (!byParent.has(p.ppid)) byParent.set(p.ppid, []);
|
|
65
|
+
byParent.get(p.ppid).push(p);
|
|
66
|
+
}
|
|
67
|
+
const out = [];
|
|
68
|
+
const stack = [rootPid];
|
|
69
|
+
const seen = new Set();
|
|
70
|
+
while (stack.length) {
|
|
71
|
+
const pid = stack.pop();
|
|
72
|
+
if (seen.has(pid)) continue;
|
|
73
|
+
seen.add(pid);
|
|
74
|
+
const self = procs.find((p) => p.pid === pid);
|
|
75
|
+
if (self) out.push(self);
|
|
76
|
+
for (const c of byParent.get(pid) || []) stack.push(c.pid);
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// kill the whole tree. We spawn the child detached, so on unix the child's pid
|
|
82
|
+
// is its process-group id and one negative-pid signal takes the lot; we still
|
|
83
|
+
// sweep the subtree in case anything escaped the group.
|
|
84
|
+
function killTree(rootPid) {
|
|
85
|
+
if (isWin) {
|
|
86
|
+
try { cp.execFileSync('taskkill', ['/PID', String(rootPid), '/T', '/F'], { stdio: 'ignore' }); } catch {}
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
try { process.kill(-rootPid, 'SIGKILL'); } catch {}
|
|
90
|
+
for (const p of subtree(rootPid)) {
|
|
91
|
+
try { process.kill(p.pid, 'SIGKILL'); } catch {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// best-effort cooperative pause of the tree while the user is prompted
|
|
96
|
+
function pauseTree(rootPid) {
|
|
97
|
+
if (isWin) return; // no portable suspend in v0.1; the hook already blocks at source
|
|
98
|
+
try { process.kill(-rootPid, 'SIGSTOP'); } catch {}
|
|
99
|
+
}
|
|
100
|
+
function resumeTree(rootPid) {
|
|
101
|
+
if (isWin) return;
|
|
102
|
+
try { process.kill(-rootPid, 'SIGCONT'); } catch {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// shells / runtimes that are suspicious if they appear inside an install tree
|
|
106
|
+
const SUSPECT = new Set(['sh', 'bash', 'zsh', 'dash', 'cmd.exe', 'powershell.exe', 'pwsh',
|
|
107
|
+
'curl', 'wget', 'nc', 'ncat', 'bun', 'deno']);
|
|
108
|
+
function suspectComm(comm) {
|
|
109
|
+
return SUSPECT.has(String(comm || '').toLowerCase());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = { listProcesses, subtree, killTree, pauseTree, resumeTree, suspectComm };
|
package/lib/store.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Read/write the USER policy file (~/.sentrion/policy.json). This is the single
|
|
3
|
+
// place that mutates on-disk state for `mode`, `trust`/`untrust`, `allow` and
|
|
4
|
+
// the P (always-trust) prompt. Zero dependencies.
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const os = require('os');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
function dir() { return path.join(os.homedir(), '.sentrion'); }
|
|
11
|
+
function file() { return path.join(dir(), 'policy.json'); }
|
|
12
|
+
function listsDir() { return path.join(dir(), 'lists'); }
|
|
13
|
+
|
|
14
|
+
function read() {
|
|
15
|
+
try { return JSON.parse(fs.readFileSync(file(), 'utf8')); }
|
|
16
|
+
catch { return {}; }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function write(obj) {
|
|
20
|
+
fs.mkdirSync(dir(), { recursive: true });
|
|
21
|
+
fs.writeFileSync(file(), JSON.stringify(obj, null, 2) + '\n');
|
|
22
|
+
return file();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// mutate the user policy with a callback, persist, return the file path
|
|
26
|
+
function update(fn) {
|
|
27
|
+
const o = read();
|
|
28
|
+
fn(o);
|
|
29
|
+
return write(o);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = { dir, file, listsDir, read, write, update };
|
package/lib/ui.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Small terminal helpers: colour, the SENTRION badge (orange X), and the
|
|
3
|
+
// K / A / P prompt. Zero dependencies.
|
|
4
|
+
|
|
5
|
+
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
6
|
+
const C = (code) => (s) => (useColor ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
7
|
+
|
|
8
|
+
const c = {
|
|
9
|
+
dim: C('2;37'), white: C('97'), bold: C('1'),
|
|
10
|
+
green: C('32'), yellow: C('33'), red: C('31'), cyan: C('36'),
|
|
11
|
+
blueBg: C('44;97'), orange: C('38;5;208'), redBg: C('41;97'),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// "SENTRION" with a blue tag and an orange X
|
|
15
|
+
function badge() {
|
|
16
|
+
const name = c.white('SENTRI') + c.orange('X');
|
|
17
|
+
return (useColor ? `\x1b[44m \x1b[0m` : '') + c.blueBg(' SENTRI') + c.orange('X') + c.blueBg(' ');
|
|
18
|
+
}
|
|
19
|
+
function tag() {
|
|
20
|
+
// blue background block: "SENTRI" white + "X" orange, on blue
|
|
21
|
+
if (!useColor) return '[ SENTRION ]';
|
|
22
|
+
return `\x1b[44;97m SENTRI\x1b[44;38;5;208mX\x1b[44;97m \x1b[0m`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const sev = {
|
|
26
|
+
critical: c.red, high: c.red, medium: c.yellow, low: c.dim,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// read a single key (K/A/P/D) from the TTY, with a timeout → default 'K'
|
|
30
|
+
function promptKAP(timeoutSec) {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const stdin = process.stdin;
|
|
33
|
+
if (!stdin.isTTY) return resolve('K');
|
|
34
|
+
let done = false;
|
|
35
|
+
const finish = (val) => {
|
|
36
|
+
if (done) return; done = true;
|
|
37
|
+
try { stdin.setRawMode(false); } catch {}
|
|
38
|
+
stdin.pause();
|
|
39
|
+
stdin.removeListener('data', onData);
|
|
40
|
+
clearInterval(timer);
|
|
41
|
+
process.stdout.write('\n');
|
|
42
|
+
resolve(val);
|
|
43
|
+
};
|
|
44
|
+
let left = timeoutSec;
|
|
45
|
+
const render = () => {
|
|
46
|
+
process.stdout.write(`\r ${c.redBg(' K ')} kill ${c.bold('A')} allow once ${c.bold('P')} always trust ${c.dim('[' + left + 's → kill]')} > `);
|
|
47
|
+
};
|
|
48
|
+
const onData = (buf) => {
|
|
49
|
+
const k = buf.toString().trim().toUpperCase();
|
|
50
|
+
if (k === 'K' || k === '\u0003') finish('K');
|
|
51
|
+
else if (k === 'A') finish('A');
|
|
52
|
+
else if (k === 'P') finish('P');
|
|
53
|
+
// ignore other keys
|
|
54
|
+
};
|
|
55
|
+
try { stdin.setRawMode(true); } catch {}
|
|
56
|
+
stdin.resume();
|
|
57
|
+
stdin.on('data', onData);
|
|
58
|
+
render();
|
|
59
|
+
const timer = setInterval(() => { left -= 1; if (left <= 0) finish('K'); else render(); }, 1000);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = { c, tag, badge, sev, promptKAP, useColor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sentrion",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "A live guard for developer machines: prefix any command (npm/pnpm/yarn/bun install, or running code in any language) with `sentrion` and it scans, watches and blocks malicious install scripts, credential theft, backdoors and privilege escalation — with a Kill/Allow prompt and a readable incident report.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"security",
|
|
7
|
+
"supply-chain",
|
|
8
|
+
"npm",
|
|
9
|
+
"malware",
|
|
10
|
+
"install-guard",
|
|
11
|
+
"sandbox",
|
|
12
|
+
"postinstall",
|
|
13
|
+
"egress",
|
|
14
|
+
"devsecops",
|
|
15
|
+
"cli",
|
|
16
|
+
"runtime-security",
|
|
17
|
+
"dependency-confusion",
|
|
18
|
+
"typosquat",
|
|
19
|
+
"incident-response"
|
|
20
|
+
],
|
|
21
|
+
"homepage": "https://github.com/imeerai/sentrion#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/imeerai/sentrion/issues"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/imeerai/sentrion.git"
|
|
28
|
+
},
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "imeerai",
|
|
31
|
+
"type": "commonjs",
|
|
32
|
+
"bin": {
|
|
33
|
+
"sentrion": "bin/sentrion.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"bin",
|
|
37
|
+
"lib",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {}
|
|
45
|
+
}
|