const fs = require('fs'); const { RemoteTerminal } = require('./remote_exec'); const LOG_FILE = 'D:/cumin/ghaymah_dns_net_sec_tests/logs/uniquename_dns_tcp.log'; async function main() { const term = new RemoteTerminal(); await term.connect(); console.log('Connected to Ghaymah terminal pod!'); const logs = []; function log(title, data) { const ts = new Date().toISOString(); const str = `[${ts}] === ${title} ===\n${data}\n`; console.log(str); logs.push(str); fs.writeFileSync(LOG_FILE, logs.join('\n')); } // 1. DNS Resolution using uniqueName log('DNS: nslookup test-redis-feccbaec5bd7', (await term.exec('nslookup test-redis-feccbaec5bd7')).output); log('DNS: getent hosts test-redis-feccbaec5bd7', (await term.exec('getent hosts test-redis-feccbaec5bd7')).output); // 2. TCP Port Probe on port 6379 via DNS Hostname log('TCP: nc -z -w 3 test-redis-feccbaec5bd7 6379', (await term.exec('nc -zv -w 3 test-redis-feccbaec5bd7 6379 2>&1 || nc -z -w 3 test-redis-feccbaec5bd7 6379 && echo "PORT 6379 IS OPEN!"')).output); // 3. Raw TCP Redis Handshake log('TCP: PING test-redis-feccbaec5bd7 6379', (await term.exec('printf "*1\\r\\n\\$4\\r\\nPING\\r\\n" | nc -w 3 test-redis-feccbaec5bd7 6379')).output); // 4. Raw TCP Data Set & Get const redisCmds = `printf "*3\\r\\n\\$3\\r\\nSET\\r\\n\\$7\\r\\nghaymah\\r\\n\\$16\\r\\nINTERNAL_DNS_OK\\r\\n*2\\r\\n\\$3\\r\\nGET\\r\\n\\$7\\r\\nghaymah\\r\\n" | nc -w 3 test-redis-feccbaec5bd7 6379`; log('TCP: Redis SET & GET via DNS', (await term.exec(redisCmds)).output); // 5. Cross-Project Test to auth-deploy-4c0bca85312b (Project: auth-deploy) log('SECURITY: Cross-Project DNS (auth-deploy-4c0bca85312b)', (await term.exec('nslookup auth-deploy-4c0bca85312b')).output); log('SECURITY: Cross-Project TCP (auth-deploy-4c0bca85312b:80)', (await term.exec('nc -zv -w 3 auth-deploy-4c0bca85312b 80 2>&1 || nc -z -w 3 auth-deploy-4c0bca85312b 80 && echo "OPEN" || echo "BLOCKED"')).output); // 6. Cross-Project HTTP Request log('SECURITY: Cross-Project HTTP GET', (await term.exec('wget -qO- -T 3 http://auth-deploy-4c0bca85312b/ || echo "BLOCKED_OR_FAILED"')).output); term.close(); console.log('All tests finished! Log saved to', LOG_FILE); } main().catch(console.error);