barebox 0.1.0 → 0.3.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.
@@ -1,15 +0,0 @@
1
- bridge=up
2
- T1_through_proxy_http=200
3
- T2_connect_exit=2026/10/26 19:32:15 socat[11] E read(6, 0x5650ef344000, 8192): Connection reset by peer
4
- 35
5
- T3_ssh_visible_entries=0
6
- /usr/bin/bash: line 11: /tmp/sbx-m0/proj/nope: Read-only file system
7
- T4a_write_proj=BLOCKED
8
- /usr/bin/bash: line 12: /home/hamr/nope-m0: Read-only file system
9
- T4b_write_home=BLOCKED
10
- B1_noproxy_exit=6
11
- B2_noenv_exit=6
12
- B3_localhost_isolated_exit=7
13
- B3b_directip_exit=7
14
- B4_default_route_lines=0
15
- T5_identity_probe=404
@@ -1,15 +0,0 @@
1
- bridge=up
2
- T1_through_proxy_http=200
3
- T2_connect_exit=2026/10/26 19:32:15 socat[11] E read(6, 0x55c593ced000, 8192): Connection reset by peer
4
- 35
5
- T3_ssh_visible_entries=0
6
- /usr/bin/bash: line 11: /tmp/sbx-m0/proj/nope: Read-only file system
7
- T4a_write_proj=BLOCKED
8
- /usr/bin/bash: line 12: /home/hamr/nope-m0: Read-only file system
9
- T4b_write_home=BLOCKED
10
- B1_noproxy_exit=6
11
- B2_noenv_exit=6
12
- B3_localhost_isolated_exit=7
13
- B3b_directip_exit=7
14
- B4_default_route_lines=0
15
- T5_identity_probe=404
package/poc/m0/launch.sh DELETED
@@ -1,43 +0,0 @@
1
- #!/usr/bin/env bash
2
- # M0 POC launcher: bwrap walls + socat bridge. No overlay (that's M4).
3
- # Usage: launch.sh <runtime> <agent> <proj-fixture> <cmd...>
4
- set -u
5
- RUNTIME=$1; AGENT=$2; PROJ=$3; shift 3
6
- SOCK=$RUNTIME/socks/$AGENT.sock
7
- mkdir -p "$RUNTIME/socks"
8
-
9
- ARGS=(
10
- --unshare-pid --unshare-uts --unshare-ipc
11
- --die-with-parent
12
- --proc /proc --dev /dev --tmpfs /tmp
13
- --ro-bind /usr /usr
14
- --symlink usr/lib64 /lib64
15
- --ro-bind /etc /etc
16
- )
17
- # RED-TEAM HOOKS (throwaway POC only): SBX_BREAK=nonet|nolock|rw.
18
- # Default path is unchanged: full isolation.
19
- [ "${SBX_BREAK:-}" = nonet ] || ARGS+=(--unshare-net)
20
- if [ "${SBX_BREAK:-}" = rw ]; then
21
- ARGS+=(--bind "$PROJ" "$PROJ" --bind "$HOME" "$HOME")
22
- else
23
- ARGS+=(--ro-bind "$PROJ" "$PROJ" --ro-bind "$HOME" "$HOME")
24
- fi
25
- # Locked drawers: mask each one that exists on this host.
26
- if [ "${SBX_BREAK:-}" != nolock ]; then
27
- for p in "$HOME/.ssh" "$HOME/secrets" "$HOME/.mozilla" "$HOME/.config/chromium" "$HOME/.gnupg"; do
28
- [ -d "$p" ] && ARGS+=(--tmpfs "$p")
29
- done
30
- fi
31
- ARGS+=(
32
- --dir /run
33
- --tmpfs /run/sbx
34
- --bind "$SOCK" /run/sbx/agent.sock
35
- --setenv HOME "$HOME"
36
- --setenv PATH /usr/bin:/bin:/usr/sbin
37
- --setenv HTTP_PROXY http://127.0.0.1:3128
38
- --setenv HTTPS_PROXY http://127.0.0.1:3128
39
- --setenv http_proxy http://127.0.0.1:3128
40
- --setenv https_proxy http://127.0.0.1:3128
41
- )
42
- exec bwrap "${ARGS[@]}" \
43
- /usr/bin/bash -c 'ip link set lo up 2>/dev/null; socat TCP-LISTEN:3128,bind=127.0.0.1,reuseaddr,fork UNIX-CONNECT:/run/sbx/agent.sock & exec "$@"' bash "$@"
package/poc/m0/measure.js DELETED
@@ -1,53 +0,0 @@
1
- // M0 POC: sum RSS per sandbox process tree (bwrap roots) + proxy RSS. Node stdlib only.
2
- // Usage: node measure.js <pidfile> <proxy-pid>
3
- 'use strict';
4
- const fs = require('fs');
5
- const [, , pidfile, proxyPid] = process.argv;
6
- const kids = {};
7
- for (const d of fs.readdirSync('/proc')) {
8
- if (!/^\d+$/.test(d)) continue;
9
- try {
10
- const stat = fs.readFileSync(`/proc/${d}/stat`, 'utf8');
11
- const m = stat.match(/^\d+ \(.*\) \S+ (\d+)/);
12
- if (m) (kids[m[1]] = kids[m[1]] || []).push(d);
13
- } catch { /* raced exit */ }
14
- }
15
- const rssKb = (pid) => {
16
- try {
17
- const m = fs.readFileSync(`/proc/${pid}/status`, 'utf8').match(/^VmRSS:\s+(\d+) kB/m);
18
- return m ? +m[1] : 0;
19
- } catch { return 0; }
20
- };
21
- const comm = (pid) => {
22
- try { return fs.readFileSync(`/proc/${pid}/comm`, 'utf8').trim(); } catch { return '?exited'; }
23
- };
24
- const tree = (root) => {
25
- const out = [];
26
- const stack = [String(root)];
27
- while (stack.length) {
28
- const p = stack.pop();
29
- out.push(p);
30
- for (const k of kids[p] || []) stack.push(k);
31
- }
32
- return out;
33
- };
34
- const mb = (kb) => (kb / 1024).toFixed(1);
35
- const roots = fs.readFileSync(pidfile, 'utf8').trim().split('\n').filter(Boolean);
36
- let total = 0, totalNoSleep = 0, maxNoSleep = 0;
37
- for (const r of roots) {
38
- const members = tree(r);
39
- let sum = 0, noSleep = 0;
40
- const parts = [];
41
- for (const p of members) {
42
- const kb = rssKb(p), c = comm(p);
43
- sum += kb;
44
- if (c !== 'sleep') noSleep += kb;
45
- parts.push(`${c}=${mb(kb)}MB`);
46
- }
47
- total += sum; totalNoSleep += noSleep;
48
- if (noSleep > maxNoSleep) maxNoSleep = noSleep;
49
- console.log(`sandbox root=${r} procs=${members.length} total=${mb(sum)}MB no-sleep=${mb(noSleep)}MB [${parts.join(' ')}]`);
50
- }
51
- console.log(`count=${roots.length} sum-total=${mb(total)}MB mean-total=${mb(total / roots.length)}MB`);
52
- console.log(`sum-no-sleep=${mb(totalNoSleep)}MB mean-no-sleep=${mb(totalNoSleep / roots.length)}MB max-no-sleep=${mb(maxNoSleep)}MB`);
53
- console.log(`proxy pid=${proxyPid} rss=${mb(rssKb(proxyPid))}MB`);
@@ -1,23 +0,0 @@
1
- sandbox root=3948118 procs=4 total=9.9MB no-sleep=7.7MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
2
- sandbox root=3948119 procs=4 total=10.0MB no-sleep=7.9MB [bwrap=2.3MB bwrap=1.5MB sleep=2.1MB socat=4.1MB]
3
- sandbox root=3948120 procs=4 total=9.9MB no-sleep=7.8MB [bwrap=2.3MB bwrap=1.4MB sleep=2.1MB socat=4.1MB]
4
- sandbox root=3948121 procs=4 total=9.7MB no-sleep=7.6MB [bwrap=2.1MB bwrap=1.4MB sleep=2.1MB socat=4.0MB]
5
- sandbox root=3948122 procs=4 total=10.0MB no-sleep=7.8MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
6
- sandbox root=3948123 procs=4 total=9.8MB no-sleep=7.7MB [bwrap=2.3MB bwrap=1.4MB sleep=2.1MB socat=4.1MB]
7
- sandbox root=3948124 procs=4 total=10.0MB no-sleep=7.8MB [bwrap=2.3MB bwrap=1.5MB sleep=2.2MB socat=4.0MB]
8
- sandbox root=3948125 procs=4 total=9.9MB no-sleep=7.7MB [bwrap=2.3MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
9
- sandbox root=3948126 procs=4 total=10.0MB no-sleep=7.8MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
10
- sandbox root=3948127 procs=4 total=9.7MB no-sleep=7.5MB [bwrap=2.1MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
11
- sandbox root=3948128 procs=4 total=9.8MB no-sleep=7.7MB [bwrap=2.3MB bwrap=1.4MB sleep=2.1MB socat=4.1MB]
12
- sandbox root=3948129 procs=4 total=9.8MB no-sleep=7.6MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
13
- sandbox root=3948130 procs=4 total=9.9MB no-sleep=7.7MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
14
- sandbox root=3948131 procs=4 total=9.8MB no-sleep=7.7MB [bwrap=2.2MB bwrap=1.4MB sleep=2.1MB socat=4.1MB]
15
- sandbox root=3948135 procs=4 total=10.0MB no-sleep=7.8MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
16
- sandbox root=3948136 procs=4 total=9.9MB no-sleep=7.8MB [bwrap=2.3MB bwrap=1.4MB sleep=2.1MB socat=4.0MB]
17
- sandbox root=3948138 procs=4 total=9.9MB no-sleep=7.7MB [bwrap=2.2MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
18
- sandbox root=3948139 procs=4 total=9.8MB no-sleep=7.7MB [bwrap=2.2MB bwrap=1.4MB sleep=2.1MB socat=4.1MB]
19
- sandbox root=3948141 procs=4 total=10.1MB no-sleep=7.9MB [bwrap=2.3MB bwrap=1.4MB sleep=2.2MB socat=4.1MB]
20
- sandbox root=3948143 procs=4 total=10.0MB no-sleep=7.8MB [bwrap=2.3MB bwrap=1.3MB sleep=2.2MB socat=4.1MB]
21
- count=20 sum-total=197.9MB mean-total=9.9MB
22
- sum-no-sleep=154.4MB mean-no-sleep=7.7MB max-no-sleep=7.9MB
23
- proxy pid=3948091 rss=52.1MB
package/poc/m0/proxy.js DELETED
@@ -1,74 +0,0 @@
1
- // M0 POC: dumb forward + CONNECT proxy on per-agent unix sockets. Allow-all, stdlib only.
2
- // Usage: node proxy.js <sockdir> <agent...>
3
- // Log: "<iso> <agent> <method> <url> -> <status|tunnel|error>"
4
- 'use strict';
5
- const http = require('http');
6
- const net = require('net');
7
- const fs = require('fs');
8
- const path = require('path');
9
-
10
- const [, , sockdir, ...agents] = process.argv;
11
- if (!sockdir || agents.length === 0) {
12
- console.error('usage: node proxy.js <sockdir> <agent...>');
13
- process.exit(1);
14
- }
15
- fs.mkdirSync(sockdir, { recursive: true });
16
- const log = (agent, msg) => console.log(`${new Date().toISOString()} ${agent} ${msg}`);
17
-
18
- for (const agent of agents) {
19
- const sock = path.join(sockdir, `${agent}.sock`);
20
- try { fs.unlinkSync(sock); } catch { /* fresh start */ }
21
- const server = http.createServer((req, res) => {
22
- let target;
23
- try {
24
- target = new URL(req.url);
25
- } catch {
26
- res.writeHead(400, { 'content-type': 'text/plain' });
27
- res.end('bad url (M0 POC expects absolute URI)\n');
28
- return;
29
- }
30
- if (target.protocol !== 'http:') {
31
- res.writeHead(400, { 'content-type': 'text/plain' });
32
- res.end('M0 POC forwards http only; https uses CONNECT\n');
33
- return;
34
- }
35
- const headers = { ...req.headers, host: target.host };
36
- delete headers['proxy-connection'];
37
- const up = http.request(
38
- {
39
- host: target.hostname,
40
- port: target.port || 80,
41
- path: target.pathname + target.search,
42
- method: req.method,
43
- headers,
44
- },
45
- (upRes) => {
46
- res.writeHead(upRes.statusCode, upRes.headers);
47
- upRes.pipe(res);
48
- log(agent, `${req.method} ${req.url} -> ${upRes.statusCode}`);
49
- }
50
- );
51
- up.on('error', (e) => {
52
- if (!res.headersSent) res.writeHead(502, { 'content-type': 'text/plain' });
53
- res.end(`proxy error: ${e.code || e.message}\n`);
54
- log(agent, `${req.method} ${req.url} -> error ${e.code || e.message}`);
55
- });
56
- req.pipe(up);
57
- });
58
- server.on('connect', (req, socket, head) => {
59
- const [host, port] = req.url.split(':');
60
- const upstream = net.connect(port || 443, host, () => {
61
- socket.write('HTTP/1.1 200 Connection established\r\n\r\n');
62
- if (head && head.length) upstream.write(head);
63
- socket.pipe(upstream).pipe(socket);
64
- log(agent, `CONNECT ${req.url} -> tunnel`);
65
- });
66
- upstream.on('error', (e) => {
67
- socket.write('HTTP/1.1 502 Bad Gateway\r\n\r\n');
68
- socket.destroy();
69
- log(agent, `CONNECT ${req.url} -> error ${e.code || e.message}`);
70
- });
71
- socket.on('error', () => upstream.destroy());
72
- });
73
- server.listen(sock, () => log(agent, `listening on ${sock}`));
74
- }
package/poc/m0/proxy.log DELETED
@@ -1,28 +0,0 @@
1
- 2026-10-26T18:32:13.151Z a01 listening on /tmp/sbx-m0/socks/a01.sock
2
- 2026-10-26T18:32:13.153Z a02 listening on /tmp/sbx-m0/socks/a02.sock
3
- 2026-10-26T18:32:13.153Z a03 listening on /tmp/sbx-m0/socks/a03.sock
4
- 2026-10-26T18:32:13.153Z a04 listening on /tmp/sbx-m0/socks/a04.sock
5
- 2026-10-26T18:32:13.153Z a05 listening on /tmp/sbx-m0/socks/a05.sock
6
- 2026-10-26T18:32:13.153Z a06 listening on /tmp/sbx-m0/socks/a06.sock
7
- 2026-10-26T18:32:13.154Z a07 listening on /tmp/sbx-m0/socks/a07.sock
8
- 2026-10-26T18:32:13.154Z a08 listening on /tmp/sbx-m0/socks/a08.sock
9
- 2026-10-26T18:32:13.154Z a09 listening on /tmp/sbx-m0/socks/a09.sock
10
- 2026-10-26T18:32:13.154Z a10 listening on /tmp/sbx-m0/socks/a10.sock
11
- 2026-10-26T18:32:13.154Z a11 listening on /tmp/sbx-m0/socks/a11.sock
12
- 2026-10-26T18:32:13.154Z a12 listening on /tmp/sbx-m0/socks/a12.sock
13
- 2026-10-26T18:32:13.154Z a13 listening on /tmp/sbx-m0/socks/a13.sock
14
- 2026-10-26T18:32:13.154Z a14 listening on /tmp/sbx-m0/socks/a14.sock
15
- 2026-10-26T18:32:13.154Z a15 listening on /tmp/sbx-m0/socks/a15.sock
16
- 2026-10-26T18:32:13.154Z a16 listening on /tmp/sbx-m0/socks/a16.sock
17
- 2026-10-26T18:32:13.154Z a17 listening on /tmp/sbx-m0/socks/a17.sock
18
- 2026-10-26T18:32:13.154Z a18 listening on /tmp/sbx-m0/socks/a18.sock
19
- 2026-10-26T18:32:13.154Z a19 listening on /tmp/sbx-m0/socks/a19.sock
20
- 2026-10-26T18:32:13.154Z a20 listening on /tmp/sbx-m0/socks/a20.sock
21
- 2026-10-26T18:32:13.154Z fx listening on /tmp/sbx-m0/socks/fx.sock
22
- 2026-10-26T18:32:13.154Z fy listening on /tmp/sbx-m0/socks/fy.sock
23
- 2026-10-26T18:32:15.602Z fx GET http://127.0.0.1:18080/ -> 200
24
- 2026-10-26T18:32:15.610Z fx CONNECT 127.0.0.1:18080 -> tunnel
25
- 2026-10-26T18:32:15.650Z fx GET http://127.0.0.1:18080/fx-probe -> 404
26
- 2026-10-26T18:32:15.677Z fy GET http://127.0.0.1:18080/ -> 200
27
- 2026-10-26T18:32:15.685Z fy CONNECT 127.0.0.1:18080 -> tunnel
28
- 2026-10-26T18:32:15.720Z fy GET http://127.0.0.1:18080/fy-probe -> 404
@@ -1,4 +0,0 @@
1
- sandbox root=3995975 procs=4 total=69.5MB no-sleep=69.5MB [bwrap=2.2MB bwrap=1.4MB python3=61.7MB socat=4.1MB]
2
- count=1 sum-total=69.5MB mean-total=69.5MB
3
- sum-no-sleep=69.5MB mean-no-sleep=69.5MB max-no-sleep=69.5MB
4
- proxy pid=3995835 rss=53.6MB
@@ -1,13 +0,0 @@
1
- 2026-10-26T18:49:09.198Z net1 listening on /tmp/sbx-m0/socks/net1.sock
2
- 2026-10-26T18:49:09.200Z lock1 listening on /tmp/sbx-m0/socks/lock1.sock
3
- 2026-10-26T18:49:09.200Z rw1 listening on /tmp/sbx-m0/socks/rw1.sock
4
- 2026-10-26T18:49:09.200Z bravo listening on /tmp/sbx-m0/socks/bravo.sock
5
- 2026-10-26T18:49:09.200Z mem1 listening on /tmp/sbx-m0/socks/mem1.sock
6
- 2026-10-26T18:49:09.475Z net1 GET http://127.0.0.1:18080/ -> 200
7
- 2026-10-26T18:49:09.510Z net1 GET http://127.0.0.1:18080/net1-probe -> 404
8
- 2026-10-26T18:49:09.552Z lock1 GET http://127.0.0.1:18080/ -> 200
9
- 2026-10-26T18:49:09.578Z lock1 GET http://127.0.0.1:18080/lock1-probe -> 404
10
- 2026-10-26T18:49:09.610Z rw1 GET http://127.0.0.1:18080/ -> 200
11
- 2026-10-26T18:49:09.635Z rw1 GET http://127.0.0.1:18080/rw1-probe -> 404
12
- 2026-10-26T18:49:09.664Z bravo GET http://127.0.0.1:18080/ -> 200
13
- 2026-10-26T18:49:09.688Z bravo GET http://127.0.0.1:18080/alpha-probe -> 404
package/poc/m0/redteam.sh DELETED
@@ -1,118 +0,0 @@
1
- #!/usr/bin/env bash
2
- # RED-TEAM ritual for M0: break each wall on purpose; PASS iff every break is DETECTED.
3
- # SBXTEST mirrors run-m0.sh. Throwaway POC, not shipped.
4
- set -u
5
- R=/tmp/sbx-m0
6
- PROJ=$R/proj
7
- PROXY_PID=""; HTTPD_PID=""
8
- TARGET_M0="http://127.0.0.1:18080"
9
- RED_FAIL=0
10
- detect() { echo "DETECTED: $1"; }
11
- miss() { echo "MISSED: $1"; RED_FAIL=1; }
12
-
13
- cleanup() {
14
- [ -n "$PROXY_PID" ] && kill "$PROXY_PID" 2>/dev/null || true
15
- [ -n "$HTTPD_PID" ] && kill "$HTTPD_PID" 2>/dev/null || true
16
- if [ -f "$R/red.pids" ]; then
17
- while read -r p; do kill "$p" 2>/dev/null || true; done < "$R/red.pids"
18
- fi
19
- rm -f "$HOME/nope-m0" "$PROJ/nope"
20
- }
21
- trap cleanup EXIT
22
-
23
- HOST_SSH=$(ls -A ~/.ssh 2>/dev/null | wc -l)
24
- echo "host ~/.ssh entries: $HOST_SSH"
25
-
26
- node "$R/proxy.js" "$R/socks" net1 lock1 rw1 bravo mem1 >"$R/red-proxy.log" 2>&1 &
27
- PROXY_PID=$!
28
- for i in $(seq 1 100); do
29
- n=$(ls "$R/socks"/net1.sock "$R/socks"/lock1.sock "$R/socks"/rw1.sock "$R/socks"/bravo.sock "$R/socks"/mem1.sock 2>/dev/null | wc -l)
30
- [ "$n" = 5 ] && break
31
- [ "$i" = 100 ] && { miss "red proxy sockets (got $n/5)"; cat "$R/red-proxy.log"; exit 1; }
32
- sleep 0.1
33
- done
34
- echo "red proxy up pid=$PROXY_PID"
35
-
36
- python3 -m http.server 18080 --bind 127.0.0.1 --directory "$PROJ" >"$R/red-httpd.log" 2>&1 &
37
- HTTPD_PID=$!
38
- for i in $(seq 1 100); do
39
- if curl -s -o /dev/null --noproxy "*" --max-time 1 "$TARGET_M0/" 2>/dev/null; then break; fi
40
- [ "$i" = 100 ] && { miss "local httpd up"; cat "$R/red-httpd.log"; exit 1; }
41
- sleep 0.1
42
- done
43
- echo "local httpd up pid=$HTTPD_PID"
44
-
45
- read -r -d '' SBXTEST <<'EOF' || true
46
- ok=0
47
- for i in $(seq 1 50); do
48
- if curl -s -o /dev/null --noproxy "*" --max-time 1 http://127.0.0.1:3128/ 2>/dev/null; then ok=1; break; fi
49
- sleep 0.1
50
- done
51
- [ "$ok" = 1 ] || { echo "BRIDGE_TIMEOUT"; exit 9; }
52
- echo "bridge=up"
53
- echo -n "T1_through_proxy_http="; curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TARGET_M0/" 2>/dev/null; echo
54
- echo -n "T3_ssh_visible_entries="; ls -A "$HOME/.ssh" 2>/dev/null | wc -l
55
- if echo x > "$PROJ_M0/nope" 2>/dev/null; then echo "T4a_write_proj=ALLOWED"; else echo "T4a_write_proj=BLOCKED"; fi
56
- if echo x > "$HOME/nope-m0" 2>/dev/null; then echo "T4b_write_home=ALLOWED"; else echo "T4b_write_home=BLOCKED"; fi
57
- echo -n "B1_noproxy_exit="; curl -s -o /dev/null --noproxy "*" --max-time 5 http://example.com/ 2>/dev/null; echo "$?"
58
- echo -n "B3_localhost_isolated_exit="; curl -s -o /dev/null --noproxy "*" --max-time 5 "$TARGET_M0/" 2>/dev/null; echo "$?"
59
- echo -n "B4_default_route_lines="; awk 'NR>1 && $2=="00000000" {c++} END {print c+0}' /proc/net/route
60
- echo -n "T5_identity_probe="; curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TARGET_M0/$AGENT_M0-probe" 2>/dev/null; echo
61
- EOF
62
-
63
- run_break() { # <socket> <marker> <break-mode-or-empty> <outfile>
64
- AGENT_M0=$2 PROJ_M0=$PROJ TARGET_M0=$TARGET_M0 SBX_BREAK=$3 "$R/launch.sh" "$R" "$1" "$PROJ" /usr/bin/bash -c "$SBXTEST" >"$4" 2>&1
65
- echo "--- $4 done ---"; cat "$4"
66
- }
67
- val() { grep "^$2=" "$1" | cut -d= -f2; }
68
-
69
- # A. NET: no net namespace. Expect the host-localhost leak to be SEEN (B3==0);
70
- # front door must stay intact (T1==200).
71
- run_break net1 net1 nonet "$R/red-net.txt"
72
- B3=$(val "$R/red-net.txt" B3_localhost_isolated_exit)
73
- B4=$(val "$R/red-net.txt" B4_default_route_lines)
74
- T1=$(val "$R/red-net.txt" T1_through_proxy_http)
75
- [ "$B3" = 0 ] && detect "NET broken: host-localhost leak visible (B3=0)" || miss "NET broken but B3=$B3 (leak NOT seen)"
76
- [ "$T1" = 200 ] && detect "NET broken: front door still works (T1=200)" || miss "NET broken and T1=$T1"
77
- echo "info NET: B4=$B4 routes; B1_noproxy_exit=$(val "$R/red-net.txt" B1_noproxy_exit) (internet-dependent, not asserted)"
78
-
79
- # B. LOCK: no tmpfs masks. Expect the real dir to show through (T3 == host count).
80
- run_break lock1 lock1 nolock "$R/red-lock.txt"
81
- T3=$(val "$R/red-lock.txt" T3_ssh_visible_entries)
82
- if [ "$T3" = "$HOST_SSH" ] && [ "$HOST_SSH" != 0 ]; then detect "LOCK broken: real ~/.ssh shows through (T3=$T3)"; else miss "LOCK broken but T3=$T3 (want $HOST_SSH)"; fi
83
-
84
- # C. RW: writable binds. Expect writes to succeed (ALLOWED + ALLOWED).
85
- # Canary in the REAL $HOME; removed below and by trap.
86
- run_break rw1 rw1 rw "$R/red-rw.txt"
87
- R4A=$(val "$R/red-rw.txt" T4a_write_proj); R4B=$(val "$R/red-rw.txt" T4b_write_home)
88
- if [ "$R4A" = ALLOWED ] && [ "$R4B" = ALLOWED ]; then detect "RW broken: writes succeed (proj+home ALLOWED)"; else miss "RW broken but T4a=$R4A T4b=$R4B"; fi
89
-
90
- # D. ID: marker alpha through socket bravo (miswired launcher). Default path otherwise,
91
- # which also proves the hooked launcher still builds working sandboxes (T1==200).
92
- run_break bravo alpha "" "$R/red-id.txt"
93
- T1D=$(val "$R/red-id.txt" T1_through_proxy_http)
94
- [ "$T1D" = 200 ] && detect "default path intact after hook edit (T1=200)" || miss "hook edit broke default path (T1=$T1D)"
95
- if grep -q "alpha GET http://127.0.0.1:18080/alpha-probe" "$R/red-proxy.log"; then miss "miswire: marker accepted as identity"; else detect "miswire: main identity assertion correctly FAILS"; fi
96
- if grep -q "bravo GET http://127.0.0.1:18080/alpha-probe" "$R/red-proxy.log"; then detect "miswire: traffic attributed to socket owner (bravo)"; else miss "miswire: probe missing from log entirely"; fi
97
-
98
- # E. MEM: meter must see a fat sandbox (50 MB anon alloc). Default path.
99
- "$R/launch.sh" "$R" mem1 "$PROJ" /usr/bin/python3 -c 'import time; x = bytearray(50*1024*1024); time.sleep(600)' >"$R/red-mem.log" 2>&1 &
100
- MEMPID=$!
101
- echo "$MEMPID" > "$R/red.pids"
102
- ready=0
103
- for i in $(seq 1 100); do
104
- MID=$(pgrep -P "$MEMPID" | head -1)
105
- if [ -n "$MID" ] && pgrep -P "$MID" -x python3 >/dev/null 2>&1; then ready=1; break; fi
106
- sleep 0.1
107
- done
108
- [ "$ready" = 1 ] || miss "MEM: python allocator never appeared"
109
- node "$R/measure.js" "$R/red.pids" "$PROXY_PID" | tee "$R/red-mem.txt"
110
- FAT=$(grep '^count=' "$R/red-mem.txt" | sed 's/.*sum-total=//;s/MB.*//')
111
- echo "fat-sandbox total: ${FAT}MB (gate would fire iff > 10)"
112
- if awk "BEGIN {exit !($FAT > 10)}"; then detect "MEM: meter sees fat sandbox (${FAT}MB > 10MB bar)"; else miss "MEM: meter blind (total ${FAT}MB)"; fi
113
-
114
- rm -f "$HOME/nope-m0" "$PROJ/nope"
115
- if [ -e "$HOME/nope-m0" ] || [ -e "$PROJ/nope" ]; then echo "CANARY LEFTOVER PRESENT"; RED_FAIL=1; else echo "canaries clean"; fi
116
- echo "--- red proxy identity lines ---"; grep -- 'probe' "$R/red-proxy.log"
117
- echo "REDTEAM_FAIL=$RED_FAIL"
118
- exit $RED_FAIL
package/poc/m0/run-m0.sh DELETED
@@ -1,136 +0,0 @@
1
- #!/usr/bin/env bash
2
- # M0 POC harness: proxy + 20 idle + functional + bypass. Prints evidence, exits nonzero on fail.
3
- set -u
4
- R=/tmp/sbx-m0
5
- PROJ=$R/proj
6
- PROXY_PID=""
7
- mkdir -p "$R/socks" "$PROJ"
8
- echo "real-file" > "$PROJ/a.txt"
9
- IDLE=$(printf 'a%02d ' $(seq 1 20))
10
- ALL="$IDLE fx fy"
11
- FAIL=0
12
- fail() { echo "FAIL: $1"; FAIL=1; }
13
- pass() { echo "PASS: $1"; }
14
-
15
- HTTPD_PID=""
16
- TARGET_M0="http://127.0.0.1:18080"
17
- cleanup() {
18
- [ -n "$PROXY_PID" ] && kill "$PROXY_PID" 2>/dev/null || true
19
- [ -n "$HTTPD_PID" ] && kill "$HTTPD_PID" 2>/dev/null || true
20
- if [ -f "$R/bwrap.pids" ]; then
21
- while read -r p; do kill "$p" 2>/dev/null || true; done < "$R/bwrap.pids"
22
- fi
23
- }
24
- trap cleanup EXIT
25
-
26
- echo "host ~/.ssh entries: $(ls -A ~/.ssh 2>/dev/null | wc -l) (if 0, T3 is vacuous)"
27
-
28
- node "$R/proxy.js" "$R/socks" $ALL >"$R/proxy.log" 2>&1 &
29
- PROXY_PID=$!
30
- for i in $(seq 1 100); do
31
- n=$(ls "$R/socks"/*.sock 2>/dev/null | wc -l)
32
- [ "$n" = 22 ] && break
33
- [ "$i" = 100 ] && { fail "proxy sockets (got $n/22)"; cat "$R/proxy.log"; exit 1; }
34
- sleep 0.1
35
- done
36
- echo "proxy up pid=$PROXY_PID"
37
- python3 -m http.server 18080 --bind 127.0.0.1 --directory "$PROJ" >"$R/httpd.log" 2>&1 &
38
- HTTPD_PID=$!
39
- for i in $(seq 1 100); do
40
- if curl -s -o /dev/null --noproxy "*" --max-time 1 "$TARGET_M0/" 2>/dev/null; then break; fi
41
- [ "$i" = 100 ] && { fail "local httpd up"; cat "$R/httpd.log"; exit 1; }
42
- sleep 0.1
43
- done
44
- echo "local httpd up pid=$HTTPD_PID (tool sandbox has no outbound internet; upstream is local)"
45
-
46
- S=$(date +%s%3N)
47
- "$R/launch.sh" "$R" fx "$PROJ" true
48
- E=$(date +%s%3N)
49
- echo "cold start+exit: $((E - S)) ms"
50
-
51
- : >"$R/bwrap.pids"
52
- SOCAT_BASE=$(pgrep -c -x socat || true)
53
- [ -z "$SOCAT_BASE" ] && SOCAT_BASE=0
54
- echo "baseline socat procs on box: $SOCAT_BASE"
55
- for a in $IDLE; do
56
- "$R/launch.sh" "$R" "$a" "$PROJ" sleep 600 >"$R/idle-$a.log" 2>&1 &
57
- echo $! >>"$R/bwrap.pids"
58
- done
59
- for i in $(seq 1 100); do
60
- n=$(pgrep -c -x socat || true)
61
- [ -z "$n" ] && n=0
62
- [ "$((n - SOCAT_BASE))" = 20 ] && break
63
- if [ "$i" = 100 ]; then
64
- fail "20 socat bridges (got $((n - SOCAT_BASE)) new, $n total, base $SOCAT_BASE)"
65
- echo "--- procs named socat ---"; pgrep -ax socat | head -30
66
- echo "--- full-cmdline matches (old gate saw these) ---"; pgrep -af "UNIX-CONNECT:/run/sbx/agent.sock" | head -70
67
- echo "--- comm histogram of full-cmdline matches ---"
68
- for p in $(pgrep -f "UNIX-CONNECT:/run/sbx/agent.sock"); do cat /proc/"$p"/comm 2>/dev/null; done | sort | uniq -c
69
- echo "--- bwrap pid file lines: $(wc -l < "$R/bwrap.pids"), liveness: ---"
70
- while read -r p; do if kill -0 "$p" 2>/dev/null; then echo alive; else echo DEAD; fi; done < "$R/bwrap.pids" | sort | uniq -c
71
- head -5 "$R"/idle-*.log
72
- exit 1
73
- fi
74
- sleep 0.1
75
- done
76
- echo "20 idle sandboxes up"
77
- echo "--- settled composition (full-cmdline matches by comm) ---"
78
- for p in $(pgrep -f "UNIX-CONNECT:/run/sbx/agent.sock"); do cat /proc/"$p"/comm 2>/dev/null; done | sort | uniq -c
79
- sleep 2
80
- node "$R/measure.js" "$R/bwrap.pids" "$PROXY_PID" | tee "$R/measure.txt"
81
-
82
- # --- functional + bypass test, runs INSIDE one sandbox ---
83
- read -r -d '' SBXTEST <<'EOF' || true
84
- ok=0
85
- for i in $(seq 1 50); do
86
- if curl -s -o /dev/null --noproxy "*" --max-time 1 http://127.0.0.1:3128/ 2>/dev/null; then ok=1; break; fi
87
- sleep 0.1
88
- done
89
- [ "$ok" = 1 ] || { echo "BRIDGE_TIMEOUT"; exit 9; }
90
- echo "bridge=up"
91
- echo -n "T1_through_proxy_http="; curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TARGET_M0/" 2>/dev/null; echo
92
- echo -n "T2_connect_exit="; curl -s -o /dev/null -k --max-time 10 "https://127.0.0.1:18080/" 2>/dev/null; echo "$?"
93
- echo -n "T3_ssh_visible_entries="; ls -A "$HOME/.ssh" 2>/dev/null | wc -l
94
- if echo x > "$PROJ_M0/nope" 2>/dev/null; then echo "T4a_write_proj=ALLOWED"; else echo "T4a_write_proj=BLOCKED"; fi
95
- if echo x > "$HOME/nope-m0" 2>/dev/null; then echo "T4b_write_home=ALLOWED"; else echo "T4b_write_home=BLOCKED"; fi
96
- echo -n "B1_noproxy_exit="; curl -s -o /dev/null --noproxy "*" --max-time 5 http://example.com/ 2>/dev/null; echo "$?"
97
- echo -n "B2_noenv_exit="; env -u HTTP_PROXY -u HTTPS_PROXY -u http_proxy -u https_proxy curl -s -o /dev/null --max-time 5 http://example.com/ 2>/dev/null; echo "$?"
98
- echo -n "B3_localhost_isolated_exit="; curl -s -o /dev/null --noproxy "*" --max-time 5 "$TARGET_M0/" 2>/dev/null; echo "$?"
99
- echo -n "B3b_directip_exit="; curl -s -o /dev/null --noproxy "*" --max-time 5 http://93.184.216.34/ 2>/dev/null; echo "$?"
100
- echo -n "B4_default_route_lines="; awk 'NR>1 && $2=="00000000" {c++} END {print c+0}' /proc/net/route
101
- echo -n "T5_identity_probe="; curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$TARGET_M0/$AGENT_M0-probe" 2>/dev/null; echo
102
- EOF
103
-
104
- run_probe() {
105
- AGENT_M0=$1 PROJ_M0=$PROJ TARGET_M0=$TARGET_M0 "$R/launch.sh" "$R" "$1" "$PROJ" /usr/bin/bash -c "$SBXTEST" >"$R/func-$1.txt" 2>&1
106
- echo "--- func $1 ---"; cat "$R/func-$1.txt"
107
- }
108
- run_probe fx
109
- run_probe fy
110
-
111
- check() {
112
- v=$(grep "^$2=" "$1" | cut -d= -f2)
113
- if [ "$v" = "$3" ]; then pass "$4 ($2=$v)"; else fail "$4 ($2=$v, want $3)"; fi
114
- }
115
- check "$R/func-fx.txt" T1_through_proxy_http 200 "fx http via proxy"
116
- if grep -q "CONNECT 127.0.0.1:18080 -> tunnel" "$R/proxy.log"; then pass "CONNECT tunnel mechanics (see log)"; else fail "CONNECT tunnel mechanics (no tunnel in log)"; fi
117
- check "$R/func-fx.txt" T3_ssh_visible_entries 0 "fx ~/.ssh masked"
118
- check "$R/func-fx.txt" T4a_write_proj BLOCKED "fx project read-only"
119
- check "$R/func-fx.txt" T4b_write_home BLOCKED "fx home read-only"
120
- check "$R/func-fx.txt" B4_default_route_lines 0 "fx no default route"
121
- for t in B1_noproxy_exit B2_noenv_exit B3_localhost_isolated_exit B3b_directip_exit; do
122
- v=$(grep "^$t=" "$R/func-fx.txt" | cut -d= -f2)
123
- if [ "$v" != 0 ]; then pass "fx $t=$v (blocked)"; else fail "fx $t=0 (LEAKED)"; fi
124
- done
125
- grep -q "fx GET http://127.0.0.1:18080/fx-probe" "$R/proxy.log" && pass "identity fx" || fail "identity fx"
126
- grep -q "fy GET http://127.0.0.1:18080/fy-probe" "$R/proxy.log" && pass "identity fy" || fail "identity fy"
127
- if grep "fx-probe" "$R/proxy.log" | grep -vq " fx "; then fail "cross-attribution on fx-probe"; else pass "no cross-attribution"; fi
128
-
129
- MEAN=$(grep '^sum-no-sleep=' "$R/measure.txt" | sed 's/.*mean-no-sleep=//;s/MB.*//')
130
- MAXV=$(grep '^sum-no-sleep=' "$R/measure.txt" | sed 's/.*max-no-sleep=//;s/MB//')
131
- echo "walls-only overhead: mean=${MEAN}MB max=${MAXV}MB (target: each <= 10MB)"
132
- if awk "BEGIN {exit !($MAXV <= 10)}"; then pass "memory target (max ${MAXV} <= 10)"; else fail "memory target (max ${MAXV} > 10)"; fi
133
-
134
- echo "--- proxy log (first 15) ---"; head -15 "$R/proxy.log"
135
- echo "RESULT_FAIL=$FAIL"
136
- exit $FAIL