code wiki / _hdl_build / nx_inet_fetch_deploy.nx

nx_inet_fetch_deploy.nx source

↩ module page · 37 lines · 2493 B

1// nx_inet_fetch_deploy.nx -- deploy the team's sovereign fetch ELF to the NAS (which HAS internet egress) and 2// RUN it there, so the team's OWN client reaches the real internet. This is the team's remote-execution 3// capability: ssh_put the binary -> chmod +x -> run -> stream its output back. The egress host is a real-world 4// dependency the operator provides (the NAS); the FETCH itself is 100% the team's sovereign code. The password 5// is read from /tmp/nxpw (written by the runner, deleted after) -- never stored. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_ssh_lib.nx" 8import "nx_ssh_put_lib.nx" 9 10func main() -> i64 { 11 let pwbox: *i64 = sys_mmap(16) as *i64 12 let pw: *u8 = sys_read_file("/tmp/nxpw" as *u8, pwbox) 13 if (pw as i64) == 0 { ssh_puts("no /tmp/nxpw\n" as *u8); return 1 } 14 var pwlen: i64 = pwbox[0] 15 while pwlen > 0 { if pw[pwlen-1] == 10 as u8 { pwlen = pwlen - 1 } else { if pw[pwlen-1] == 13 as u8 { pwlen = pwlen - 1 } else { break } } } 16 17 let st: *SshState = sys_mmap(SSH_STATE_BYTES) as *SshState 18 if ssh_open_session(st, (192 << 24) | (168 << 16) | (8 << 8) | 227) != 0 { ssh_puts("session fail\n" as *u8); return 2 } 19 if ssh_userauth_password(st, "elderwesto" as *u8, 10, pw, pwlen) != 1 { ssh_puts("auth fail\n" as *u8); sys_close(st.fd); return 3 } 20 ssh_puts("[auth ok] deploying the team's SOVEREIGN fetch ELF to the NAS (real egress host)\n" as *u8) 21 22 // read the fetch ELF built here, stream it to the NAS as raw bytes 23 let ebox: *i64 = sys_mmap(16) as *i64 24 let elf: *u8 = sys_read_file("/tmp/nx_inet_fetch.elf" as *u8, ebox) 25 if (elf as i64) == 0 { ssh_puts("missing /tmp/nx_inet_fetch.elf (build it first)\n" as *u8); sys_close(st.fd); return 4 } 26 let elen: i64 = ebox[0] 27 ssh_puts(" fetch-ELF bytes deploying: " as *u8) 28 // NAS /tmp is mounted noexec (Synology) -> deploy into the home volume which allows execution. 29 let wcmd: *u8 = "cat > /volume1/homes/elderwesto/.nx_inet_fetch.elf" as *u8 30 sshp_put_file(st, wcmd, sshp_slen(wcmd), elf, elen) 31 32 // chmod + RUN the team's sovereign fetch ON the NAS -> it reaches the real internet, prints what it sees 33 let rcmd: *u8 = "chmod +x /volume1/homes/elderwesto/.nx_inet_fetch.elf; echo '=== running the team fetch ON the NAS ==='; /volume1/homes/elderwesto/.nx_inet_fetch.elf; echo \"RUN-EXIT=$?\"; rm -f /volume1/homes/elderwesto/.nx_inet_fetch.elf" as *u8 34 ssh_exec(st, rcmd, sshp_slen(rcmd)) 35 sys_close(st.fd) 36 return 0 37}