code wiki / _hdl_build / nx_aw_nasrecon.nx

nx_aw_nasrecon.nx source

↩ module page · 32 lines · 1854 B

1// nx_aw_nasrecon.nx -- sovereign READ-ONLY recon of the NAS before deploying dev. Connects to the live 2// NAS (192.168.8.227) over the team's own SSH (nx_ssh_lib), auths with the password staged at /tmp/nxpw 3// (from the sovereign vault), and runs ONE read-only command: arch (can our x86-64 binary run?), hostname, 4// the nishihost dir, whether the andelinwest daemon process is alive, and the live :8443 status. ssh_exec 5// streams remote stdout/stderr straight to fd 1. No writes, no deploy. license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_ssh_lib.nx" 8 9func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 10 11func main() -> i64 { 12 let pwbox: *i64 = sys_mmap(16) as *i64 13 let pw: *u8 = sys_read_file("/tmp/nxpw" as *u8, pwbox) 14 if (pw as i64) == 0 { ssh_puts("no /tmp/nxpw\n" as *u8); return 1 } 15 var pwlen: i64 = pwbox[0] 16 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 } } } 17 18 let st: *SshState = sys_mmap(SSH_STATE_BYTES) as *SshState 19 if ssh_open_session(st, (192 << 24) | (168 << 16) | (8 << 8) | 227) != 0 { ssh_puts("session fail\n" as *u8); return 2 } 20 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 } 21 ssh_puts("[auth ok] recon:\n" as *u8) 22 23 // command is read from /tmp/nxcmd (so launch vs verify can be driven without rebuilding) 24 let cbox: *i64 = sys_mmap(16) as *i64 25 let cmd: *u8 = sys_read_file("/tmp/nxcmd" as *u8, cbox) 26 if (cmd as i64) == 0 { ssh_puts("no /tmp/nxcmd\n" as *u8); sys_close(st.fd); return 4 } 27 var clen: i64 = cbox[0] 28 while clen > 0 { if cmd[clen-1] == 10 as u8 { clen = clen - 1 } else { break } } 29 ssh_exec(st, cmd, clen) 30 sys_close(st.fd) 31 return 0 32}