LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Monitor → Network: raw IP sockets (/proc/net/raw{,6}, with the IP protocol) and packet sockets (/proc/net/packet, with ethertype and interface) next to TCP, UDP and ICMP, marked as able to see or forge traffic; build/conn-dump prints one reading
Federico Pereira7a8bbe95fcd6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bdf0b7c..9e73a06 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -29,7 +29,9 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),- **Test Bench** (`lordos-testbench`): a test pattern window that checks the display server from theoutside: frame timing and when frames really reach the screen, every key of the keyboard, themouse and wheel, and the Wayland protocols the system offers.-- **Monitor → Network shows ping (ICMP) sockets**, under the app that opened them, and the remote+- **Monitor → Network shows ping (ICMP), raw IP and packet sockets** (the last two can see or forge+ traffic: the row says so, with the protocol or ethertype and the interface), under the app that+ opened them, and the remotedesktop's own UDP ports under Remote Desktop instead of an unknown "?".- **`lordos-sysreport report`** prints the hardware of this computer and what the system made of it,as Markdown or `--json`, with no serial numbers, addresses or names: the base of Systemdiff --git a/apps/monitor/Network.jsx b/apps/monitor/Network.jsxindex 217656f..bbf599c 100644--- a/apps/monitor/Network.jsx+++ b/apps/monitor/Network.jsx@@ -82,6 +82,12 @@ function rememberGeo(c) {geoSeen.set(c.remote, { cc: c.cc, scope: c.scope, port: `${c.proto.toUpperCase()} ${c.rport}` });}+// Raw IP and packet sockets (conn.c): the protocol or ethertype by name where it's a common one.+const IP_PROTOS = { 1: 'ICMP', 2: 'IGMP', 6: 'TCP', 17: 'UDP', 41: 'IPv6', 47: 'GRE', 50: 'ESP', 58: 'ICMPv6', 89: 'OSPF', 112: 'VRRP', 132: 'SCTP', 255: 'IP' };+export const ipProtoName = (n) => IP_PROTOS[n] || `IP ${n}`;+const ETHERTYPES = { 0x0003: 'ALL', 0x0800: 'IPv4', 0x0806: 'ARP', 0x86dd: 'IPv6', 0x888e: 'EAPOL', 0x88cc: 'LLDP', 0x8100: 'VLAN', 0x88f7: 'PTP' };+export const etherName = (n) => ETHERTYPES[n] || `0x${(n || 0).toString(16).padStart(4, '0')}`;+// Groups the connections by app. Without lord-netperm's byte counters (withFirewall), bytes and// rates come from the open TCP sockets (tcp_info) and the difference with the previous reading.function useGroups(conns) {@@ -97,7 +103,7 @@ function useGroups(conns) {if (!g) {const comp = !!COMPONENTS[key] || key === 'lordos';g = { key, item: comp ? { app: key } : c, name: comp || (c.self && !c.cgApp) ? null : c.appName || c.name || '?', exe: c.exe, pids: new Set(), conns: [], hosts: new Map(),- sent: 0, recv: 0, rateTx: 0, rateRx: 0, listen: [], icmp: [], incoming: 0, verdict: 'allow', programs: new Set() };+ sent: 0, recv: 0, rateTx: 0, rateRx: 0, listen: [], icmp: [], raw: [], packet: [], incoming: 0, verdict: 'allow', programs: new Set() };apps.set(key, g);}if (c.name && c.cgApp && !c.self) g.programs.add(c.name);@@ -114,6 +120,8 @@ function useGroups(conns) {g.rateRx += rrx;if (c.dir === 'listen') { g.listen.push(c); continue; }if (c.dir === 'icmp') { g.icmp.push(c); continue; } // a ping socket: the kernel keeps no destination+ if (c.dir === 'raw') { g.raw.push(c); continue; } // raw IP (CAP_NET_RAW): lport holds the IP protocol+ if (c.dir === 'packet') { g.packet.push(c); continue; } // a packet socket (CAP_NET_RAW): ethertype and interfaceif (c.dir === 'in') g.incoming++;rememberGeo(c);const h = g.hosts.get(c.remote) || { remote: c.remote, cc: c.cc, scope: c.scope, ports: new Set(), sent: 0, recv: 0, rateTx: 0, rateRx: 0, count: 0 };@@ -289,7 +297,10 @@ function AppRow({ g, node, ctx, open, selected, onToggle, onSelect, maxBytes, tr{open && node ? <TreeChildren node={node} ctx={ctx} /> : null}{open && !kids ? <Text style={{ fontSize: 11, color: t.textDim, height: 22, ...(direction() === 'rtl' ? { paddingRight: 40 } : { paddingLeft: 40 }) }}>{[g.listen.length ? tr('monitor.net.onlyListening', { ports: g.listen.map((c) => c.lport).join(', ') }) : '',- g.icmp?.length ? tr('monitor.net.icmpSockets', { count: g.icmp.length }) : ''].filter(Boolean).join(' · ') || tr('monitor.net.noDestinations')}</Text> : null}+ g.icmp?.length ? tr('monitor.net.icmpSockets', { count: g.icmp.length }) : '',+ g.raw?.length ? tr('monitor.net.rawSockets', { what: [...new Set(g.raw.map((c) => ipProtoName(c.lport)))].join(', ') }) : '',+ g.packet?.length ? tr('monitor.net.packetSockets', { what: [...new Set(g.packet.map((c) => `${etherName(c.ethertype)}${c.iface ? ` · ${c.iface}` : ''}`))].join(', ') }) : '',+ ].filter(Boolean).join(' · ') || tr('monitor.net.noDestinations')}</Text> : null}</View>);}diff --git a/assets/locales/en/monitor.json b/assets/locales/en/monitor.jsonindex 0bb53b3..2064ae4 100644--- a/assets/locales/en/monitor.json+++ b/assets/locales/en/monitor.json@@ -409,5 +409,7 @@"net.icmpSockets": {"one": "{count} ICMP (ping) socket: the system doesn't keep its destination","other": "{count} ICMP (ping) sockets: the system doesn't keep their destination"- }+ },+ "net.rawSockets": "raw IP sockets ({what}): it can see or forge IP traffic",+ "net.packetSockets": "packet sockets ({what}): it can see or forge traffic on the network card"}diff --git a/assets/locales/es/monitor.json b/assets/locales/es/monitor.jsonindex b5ba311..9c6725b 100644--- a/assets/locales/es/monitor.json+++ b/assets/locales/es/monitor.json@@ -409,5 +409,7 @@"net.icmpSockets": {"one": "{count} socket ICMP (ping): el sistema no guarda su destino","other": "{count} sockets ICMP (ping): el sistema no guarda su destino"- }+ },+ "net.rawSockets": "sockets IP raw ({what}): puede ver o fabricar tráfico IP",+ "net.packetSockets": "sockets de paquete ({what}): puede ver o fabricar tráfico en la placa de red"}diff --git a/assets/locales/pt/monitor.json b/assets/locales/pt/monitor.jsonindex ea2436e..331613c 100644--- a/assets/locales/pt/monitor.json+++ b/assets/locales/pt/monitor.json@@ -409,5 +409,7 @@"net.icmpSockets": {"one": "{count} socket ICMP (ping): o sistema não guarda o destino","other": "{count} sockets ICMP (ping): o sistema não guarda o destino"- }+ },+ "net.rawSockets": "sockets IP raw ({what}): pode ver ou forjar tráfego IP",+ "net.packetSockets": "sockets de pacote ({what}): pode ver ou forjar tráfego na placa de rede"}diff --git a/docs/MONITOR.md b/docs/MONITOR.mdindex 3fbdf18..5f4458f 100644--- a/docs/MONITOR.md+++ b/docs/MONITOR.md@@ -44,10 +44,14 @@ the rest of the tab, and the first generation of the list.**each one's own allow/block switch** (see "Per-destination switches"); a click on a row selectsit in the right panel. Since 0.8.3 the app's name gets the row's whole width and wraps to twolines (the connection count and the denied badge sit next to the traffic bar; the column is- 336 px and the Data and Rule columns are narrower). Since 0.8.5 the list has three protocols: TCP and- UDP from `sock_diag`, and ICMP "ping" sockets from `/proc/net/icmp` and `icmp6` (`conn.c`,- `icmp_read`), shown on their app's row as "ICMP (ping)" without a destination (the kernel keeps none- for an unconnected ping socket). The remote desktop's bridge runs as the user but isn't dumpable, so+ 336 px and the Data and Rule columns are narrower). Since 0.8.5 the list covers what sits below TCP and+ UDP too (`conn.c`): TCP and UDP from `sock_diag`; ICMP "ping" sockets from `/proc/net/icmp` and `icmp6`,+ shown as "ICMP (ping)" without a destination (the kernel keeps none for an unconnected ping socket);+ raw IP sockets from `/proc/net/raw` and `raw6`, with their IP protocol (ICMP, IGMP, GRE, ESP, OSPF,+ VRRP…); and packet sockets from `/proc/net/packet`, with the ethertype (ALL, IPv4, ARP, IPv6, EAPOL,+ LLDP…) and the interface. Raw and packet sockets need `CAP_NET_RAW` and can see or forge traffic, so+ the row says so. `build/conn-dump` prints one reading for checking it by hand (on VM 116: a ping, a raw+ ICMP socket and an ARP packet socket on eth0, the last two from a process given `CAP_NET_RAW`). The remote desktop's bridge runs as the user but isn't dumpable, soits sockets can't be traced to a pid; `conn.c` gives the sockets in `lordos.service`'s root-owned`supervisor` group to Remote Desktop (its WebRTC UDP ports), instead of an unknown "?". At the bottom,the machine's traffic:diff --git a/server/Makefile b/server/Makefileindex 45ce1ee..8634e94 100644--- a/server/Makefile+++ b/server/Makefile@@ -376,6 +376,9 @@ build/map-bench: tests/map_bench.c src/monitor/map.c src/monitor/map.h src/monit# Monitor process actions (src/monitor/procctl.c): the protected list, stat parsing, a signal that# refuses a stale start time (PID reuse), TERM/KILL on a child, and the Get Info JSONtest: build/procctl-test+# one reading of Monitor → Network's sockets (tests/conn_dump.c), for checking conn.c by hand+build/conn-dump: tests/conn_dump.c src/monitor/conn.c src/monitor/mon.c src/monitor/disktemp.c src/monitor/mmdb.c src/pkg/xz.c build/obj/ui/stb.o+ $(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/conn_dump.c src/monitor/mon.c src/monitor/disktemp.c src/monitor/conn.c src/monitor/procctl.c src/monitor/mmdb.c src/pkg/xz.c src/fw/rules.c src/fw/fwmap.c src/sec/json.c src/sec/cgroup.c build/obj/ui/stb.o -lm -lpthreadbuild/procctl-test: tests/procctl_test.c src/monitor/procctl.c src/monitor/procctl.h src/monitor/mon.c src/monitor/disktemp.c src/monitor/conn.c src/monitor/mmdb.c src/pkg/xz.c build/obj/ui/stb.o$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/procctl_test.c src/monitor/procctl.c src/monitor/mon.c src/monitor/disktemp.c src/monitor/conn.c src/monitor/mmdb.c src/pkg/xz.c src/fw/rules.c src/fw/fwmap.c src/sec/json.c src/sec/cgroup.c build/obj/ui/stb.o -lm -lpthread./$@ || { rm -f $@; exit 1; }diff --git a/server/src/monitor/conn.c b/server/src/monitor/conn.cindex 32fd068..cf9a3bd 100644--- a/server/src/monitor/conn.c+++ b/server/src/monitor/conn.c@@ -27,6 +27,7 @@#include <linux/rtnetlink.h>#include <linux/sock_diag.h>#include <linux/tcp.h>+#include <net/if.h>#include <netinet/in.h>#include <stddef.h>#include <stdio.h>@@ -112,9 +113,16 @@ static int dump(int fd, int fam, int proto) {}}-/* ICMP "ping" sockets (ping(8) without privileges): sock_diag has no dump for them, the kernel lists- * them in /proc/net/icmp and icmp6 (with uid and inode, like every socket of the network namespace).- * An unconnected ping socket has no destination: only its echo identifier, kept as the local port. */+/* What sock_diag doesn't dump, read from the tables the kernel keeps per network namespace (every+ * socket, with uid and inode):+ * /proc/net/icmp, icmp6 ICMP "ping" sockets (ping(8) without privileges); an unconnected ping+ * socket has no destination, only its echo identifier (kept as sport);+ * /proc/net/raw, raw6 raw IP sockets (CAP_NET_RAW: traceroute -I, a privileged ping, routing+ * daemons); the "port" of the local address is the IP protocol (kept as sport);+ * /proc/net/packet packet sockets (CAP_NET_RAW: DHCP clients, 802.1X, LLDP, capture tools):+ * ethertype (sport) and interface index (dport).+ * They can see or forge traffic below TCP and UDP, so the Monitor lists them. */+#define PROTO_PACKET 254 /* not an IP protocol: a packet socket (AF_PACKET) */static void hex_addr(const char *h, int fam, uint8_t out[16]) {memset(out, 0, 16);int words = fam == 4 ? 1 : 4;@@ -130,7 +138,8 @@ static void hex_addr(const char *h, int fam, uint8_t out[16]) {}}-static void icmp_read(const char *path, int fam) {+/* proto: IPPROTO_ICMP (icmp, icmp6) or IPPROTO_RAW (raw, raw6) */+static void inet_table_read(const char *path, int fam, int proto) {FILE *f = fopen(path, "re");if (!f) return;char line[512], la[64], ra[64];@@ -146,7 +155,7 @@ static void icmp_read(const char *path, int fam) {k->inode = (uint32_t)inode;k->uid = uid;k->fam = (uint8_t)fam;- k->proto = fam == 4 ? IPPROTO_ICMP : IPPROTO_ICMPV6;+ k->proto = (uint8_t)(proto == IPPROTO_ICMP && fam == 6 ? IPPROTO_ICMPV6 : proto);k->state = (uint8_t)st;hex_addr(la, fam, k->src);hex_addr(ra, fam, k->dst);@@ -156,6 +165,29 @@ static void icmp_read(const char *path, int fam) {fclose(f);}+/* "sk RefCnt Type Proto Iface R Rmem User Inode" */+static void packet_table_read(void) {+ FILE *f = fopen("/proc/net/packet", "re");+ if (!f) return;+ char line[256];+ unsigned type, eth, ifx, uid;+ unsigned long inode;+ if (!fgets(line, sizeof line, f)) { fclose(f); return; }+ while (nsock < MAX_SOCK && fgets(line, sizeof line, f)) {+ if (sscanf(line, " %*s %*s %u %x %u %*s %*s %u %lu", &type, ð, &ifx, &uid, &inode) != 5 || !inode) continue;+ Sock *k = &socks[nsock++];+ memset(k, 0, sizeof *k);+ k->inode = (uint32_t)inode;+ k->uid = uid;+ k->fam = 17; /* AF_PACKET */+ k->proto = PROTO_PACKET;+ k->state = (uint8_t)type; /* SOCK_RAW 3 (with link header) or SOCK_DGRAM 2 */+ k->sport = (uint16_t)eth;+ k->dport = (uint16_t)ifx;+ }+ fclose(f);+}+static int sock_dump(void) {nsock = 0;int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_SOCK_DIAG);@@ -165,7 +197,13 @@ static int sock_dump(void) {for (int i = 0; i < 2; i++)for (int j = 0; j < 2; j++) ok |= !dump(fd, fams[i], protos[j]);close(fd);- if (ok) { icmp_read("/proc/net/icmp", 4); icmp_read("/proc/net/icmp6", 6); }+ if (ok) {+ inet_table_read("/proc/net/icmp", 4, IPPROTO_ICMP);+ inet_table_read("/proc/net/icmp6", 6, IPPROTO_ICMP);+ inet_table_read("/proc/net/raw", 4, IPPROTO_RAW);+ inet_table_read("/proc/net/raw6", 6, IPPROTO_RAW);+ packet_table_read();+ }return ok ? 0 : -1;}@@ -364,6 +402,23 @@ void conn_scan(Buf *b, const Mmdb *geo) {Sock *s = &socks[i];if (s->uid != me || !s->inode) continue;int fam = s->fam;+ Slot *psl = NULL;+ if (s->proto == PROTO_PACKET) { /* no addresses: ethertype and interface */+ psl = map_find(s->inode, 0);+ int pp = psl ? psl->pid : -1, pq = pp > 0 ? proc_info(pp) : -1;+ char ifn[IF_NAMESIZE] = "";+ if (!if_indextoname(s->dport, ifn)) ifn[0] = 0;+ mon_buf_printf(b, "%s{\"id\":%u,\"proto\":\"packet\",\"fam\":17,\"state\":\"%s\",\"dir\":\"packet\",\"ethertype\":%u,\"iface\":",+ n ? "," : "", s->inode, s->state == 3 ? "RAW" : "DGRAM", s->sport);+ mon_buf_str(b, ifn);+ mon_buf_printf(b, ",\"local\":\"\",\"lport\":0,\"remote\":\"\",\"rport\":0,\"scope\":\"local\",\"cc\":\"\",\"pid\":%d,\"self\":%s,\"name\":", pp, pp == self ? "true" : "false");+ mon_buf_str(b, pq >= 0 ? pinfo[pq].name : "");+ mon_buf_printf(b, ",\"exe\":");+ mon_buf_str(b, pq >= 0 ? pinfo[pq].exe : "");+ mon_buf_printf(b, ",\"cgApp\":\"\",\"sent\":null,\"recv\":null}");+ n++;+ continue;+ }uint8_t src[16], dst[16];memcpy(src, s->src, 16);memcpy(dst, s->dst, 16);@@ -376,14 +431,15 @@ void conn_scan(Buf *b, const Mmdb *geo) {char ls[INET6_ADDRSTRLEN], rs[INET6_ADDRSTRLEN];inet_ntop(fam == 4 ? AF_INET : AF_INET6, src, ls, sizeof ls);inet_ntop(fam == 4 ? AF_INET : AF_INET6, dst, rs, sizeof rs);- int tcp = s->proto == IPPROTO_TCP, icmp = s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6;+ int tcp = s->proto == IPPROTO_TCP, icmp = s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6, raw = s->proto == IPPROTO_RAW;const char *dir;if (icmp) dir = "icmp"; /* a ping socket: no destination known */+ else if (raw) dir = "raw"; /* raw IP: sport holds the IP protocol */else if (tcp && s->state == 10) dir = "listen";else if (!tcp && !s->dport) dir = "listen"; /* UDP without a destination: listening */else if (tcp && (listening_port[s->sport >> 3] & (1 << (s->sport & 7)))) dir = "in";else dir = "out";- int listening = !strcmp(dir, "listen") || icmp;+ int listening = !strcmp(dir, "listen") || icmp || raw;const char *sc = listening ? "local" : scope(fam, dst);char cc[3] = "";if (geo && !strcmp(sc, "internet")) mmdb_country(geo, dst, fam, cc);@@ -391,7 +447,7 @@ void conn_scan(Buf *b, const Mmdb *geo) {int pid = sl ? sl->pid : -1, pi = pid > 0 ? proc_info(pid) : -1;mon_buf_printf(b, "%s{\"id\":%u,\"proto\":\"%s\",\"fam\":%d,\"state\":\"%s\",\"dir\":\"%s\",\"local\":\"%s\",\"lport\":%u,""\"remote\":\"%s\",\"rport\":%u,\"scope\":\"%s\",\"cc\":\"%s\",\"pid\":%d,\"self\":%s,\"name\":",- n ? "," : "", s->inode, tcp ? "tcp" : icmp ? "icmp" : "udp", fam, tcp && s->state < 13 ? TCP_STATE[s->state] : (s->dport ? "CONNECTED" : "UNCONN"),+ n ? "," : "", s->inode, tcp ? "tcp" : icmp ? "icmp" : raw ? "raw" : "udp", fam, tcp && s->state < 13 ? TCP_STATE[s->state] : (s->dport ? "CONNECTED" : "UNCONN"),dir, ls, s->sport, listening ? "" : rs, s->dport, sc, cc, pid, pid == self ? "true" : "false");mon_buf_str(b, pi >= 0 ? pinfo[pi].name : "");mon_buf_printf(b, ",\"exe\":");diff --git a/server/tests/conn_dump.c b/server/tests/conn_dump.cnew file mode 100644index 0000000..5b3548f--- /dev/null+++ b/server/tests/conn_dump.c@@ -0,0 +1,16 @@+/* conn_dump.c — prints what Monitor → Network gets from src/monitor/conn.c (conn_scan): every socket of+ * the user with its protocol (TCP, UDP, ICMP, raw, packet), direction, addresses, process and app.+ * build/conn-dump one reading as JSON (for checking a change by hand, on a VM) */+#include "../src/monitor/monpriv.h"++#include <stdio.h>++int main(void) {+ Buf b = { 0 };+ conn_scan(&b, NULL);+ if (b.bad || !b.p) { fprintf(stderr, "conn-dump: no reading\n"); return 1; }+ fwrite(b.p, 1, b.n, stdout);+ putchar('\n');+ mon_buf_free(&b);+ return 0;+}