code wiki / (root) / nx_cad_nas_probe.nx

nx_cad_nas_probe.nx source

↩ module page · 49 lines · 2579 B

1// nx_cad_nas_probe.nx -- READ-ONLY NAS diagnostic over sovereign SSH (vault auth). 2// Reuses the nx_aw_push auth preamble; runs read-only commands. license_tier: ORIGINAL 3import "nx_syscalls.nx" 4import "nx_ssh_lib.nx" 5 6const P_SECRET_OUT: *u8 = "/tmp/nxsecret.out" as *u8 7const P_VAULT_NV: *u8 = "/home/elderwesto/.nishi/secrets/nas.nv" as *u8 8 9func p_run(path: *u8, a1: *u8, a2: *u8) -> i64 { 10 let pid: i64 = sys_fork() 11 if pid == 0 { 12 let argv: *i64 = sys_mmap(64) as *i64 13 argv[0] = path as i64 14 var ai: i64 = 1 15 if (a1 as i64) != 0 { argv[ai] = a1 as i64; ai = ai + 1 } 16 if (a2 as i64) != 0 { argv[ai] = a2 as i64; ai = ai + 1 } 17 argv[ai] = 0 18 let envp: *i64 = sys_mmap(16) as *i64 19 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 20 sys_execve(path, argv, envp) 21 sys_exit(127) 22 } 23 let st: *i64 = sys_mmap(16) as *i64 24 sys_wait4(pid, st, 0) 25 return (st[0] >> 8) & 0xff 26} 27func p_unlink(path: *u8) -> i64 { __syscall(263, AT_FDCWD, path, 0, 0, 0, 0) return 0 } 28func slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 29 30func main() -> i64 { 31 if p_run("_offc/nx_machine_key.elf" as *u8, 0 as *u8, 0 as *u8) != 0 { ssh_puts("probe: machine-key FAIL\n" as *u8); return 1 } 32 if p_run("_offc/nx_vault.elf" as *u8, "open" as *u8, P_VAULT_NV) != 0 { ssh_puts("probe: vault FAIL\n" as *u8); return 2 } 33 p_unlink("/tmp/nxpass" as *u8) 34 let pwbox: *i64 = sys_mmap(16) as *i64 35 let pw: *u8 = sys_read_file(P_SECRET_OUT, pwbox) 36 if (pw as i64) == 0 { ssh_puts("probe: secret FAIL\n" as *u8); return 3 } 37 var pwlen: i64 = pwbox[0] 38 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 } } } 39 40 let st: *SshState = sys_mmap(SSH_STATE_BYTES) as *SshState 41 if ssh_open_session(st, (192 << 24) | (168 << 16) | (8 << 8) | 227) != 0 { ssh_puts("probe: SSH FAIL\n" as *u8); p_unlink(P_SECRET_OUT); return 7 } 42 if ssh_userauth_password(st, "elderwesto" as *u8, 10, pw, pwlen) != 1 { ssh_puts("probe: AUTH FAIL\n" as *u8); sys_close(st.fd); p_unlink(P_SECRET_OUT); return 8 } 43 p_unlink(P_SECRET_OUT) 44 45 let cmd: *u8 = "D=/volume1/homes/elderwesto/nishihost/sites/nishifamily; rm -rf $D/hub 2>&1; echo HUB_REMOVED; sleep 14; echo =SUPLOG=; tail -7 /volume1/homes/elderwesto/nishihost/supervisor.log 2>&1; echo =SITESLOG=; tail -4 /tmp/sites_run.log 2>&1; echo =PROBEDONE=" as *u8 46 ssh_exec(st, cmd, slen(cmd)) 47 sys_close(st.fd) 48 return 0 49}