Node.js is Web Scale

点击"打开/下载题目"进去看看情况:

为了方便查看翻译成中文简体来看:


emmm,看不懂什么意思,查看源代码,js表示是一段JavaScript代码,丢给AI分析一下:

复制代码
// server.js
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const { execSync } = require("child_process");

const app = express();
app.use(bodyParser.json());
app.use(express.static(path.join(__dirname, "public")));

let cmds = {
  getsource: "cat server.js",
  test: "echo 'hello, world!'",
};

let store = {};

// GET /api/store - Retrieve the current KV store
app.get("/api/store", (req, res) => {
  res.json(store);
});

// POST /set - Set a key-value pair in the store
app.post("/set", (req, res) => {
  const { key, value } = req.body;

  const keys = key.split(".");
  let current = store;

  for (let i = 0; i < keys.length - 1; i++) {
    const key = keys[i];
    if (!current[key]) {
      current[key] = {};
    }
    current = current[key];
  }

  // Set the value at the last key
  current[keys[keys.length - 1]] = value;

  res.json({ message: "OK" });
});

// GET /get - Get a key-value pair in the store
app.get("/get", (req, res) => {
  const key = req.query.key;
  const keys = key.split(".");

  let current = store;
  for (let i = 0; i < keys.length; i++) {
    const key = keys[i];
    if (current[key] === undefined) {
      res.json({ message: "Not exists." });
      return;
    }
    current = current[key];
  }

  res.json({ message: current });
});

// GET /execute - Run commands which are constant and obviously safe.
app.get("/execute", (req, res) => {
  const key = req.query.cmd;
  const cmd = cmds[key];
  res.setHeader("content-type", "text/plain");
  res.send(execSync(cmd).toString());
});

app.get("*", (req, res) => {
  res.sendFile(path.join(__dirname, "public", "index.html"));
});

// Start the server
const PORT = 3000;
app.listen(PORT, () => {
  console.log(`KV Service is running on port ${PORT}`);
});

这段代码实现了一个简单的键值对存储服务(KV Store)和一个命令执行功能:

  1. 引入依赖

express: 用于创建Web服务器。

body-parser: 用于解析HTTP请求体中的JSON数据。

path: 用于处理文件路径。

child_process.execSync: 用于同步执行系统命令。


  1. 初始化应用

创建Express应用实例。

使用bodyParser.json()中间件来解析JSON格式的请求体。

设置静态文件目录为public,这样可以访问放在public目录下的静态文件。


  1. 定义命令

cmds对象定义了一些安全的命令及其对应的系统命令字符串。例如:

getsource: 获取server.js文件的内容。

test: 输出hello, world!。


  1. 键值对存储功能

GET /api/store: 返回当前键值对存储的内容。


POST /set: 设置一个键值对。支持嵌套键,例如a.b.c。

解析请求体中的key和value。

使用递归的方式在store对象中创建嵌套结构并设置值。


GET /get: 获取一个键值对。

解析查询参数中的key。

按照.分割键,逐层查找store对象中的值。

如果键不存在,返回Not exists.;否则返回对应的值。


  1. 命令执行功能

GET /execute: 执行预定义的安全命令。

解析查询参数中的cmd。

从cmds对象中获取对应的命令字符串。

使用execSync同步执行命令,并将结果以纯文本形式返回。


  1. 路由处理

GET /*: 处理所有其他路由请求,返回public目录下的index.html文件。


  1. 启动服务器

监听端口3000,并在控制台输出启动信息。


回顾一下关键代码部分:

说明会直接执行预定义的命令"cat server.js"


这下思路有了,只要想办法修改预定义的命令为cat /flag就行了

此处,我先学会儿原型链污染的知识,再回来解释


将key设置为__proto__.nanyuan,value设置为cat /flag

成功解析cat /flag


访问/execute?cmd=nanyuan,页面发生变化,并显示出flag:

成功得到flag

相关推荐
数安旭说5 小时前
从“堆叠工具”到“一体化治理”:端点安全的技术演进与实践观察
网络安全·系统架构·数据安全·企业安全·端点安全·防泄密·一体化管理
白猫不黑6 小时前
Python实现简易Web弱口令爆破与防护方案
python·web安全·计算机·网络安全·黑客·信息安全·渗透测试
迪康Defender7 小时前
终端安全实战:如何高效解决企业U盘泄密与管控难题
运维·网络·安全·web安全·终端安全管理
网安小学生(兼顾数据库版)7 小时前
固件+软件供应链:ONEKEY+Mend如何实现全链路安全覆盖
网络·安全·web安全
菩提小狗9 小时前
每日安全情报报告 · 2026-09-17
网络安全·漏洞·cve·安全情报·每日安全
虹科数字化与AR10 小时前
FME与Python脚本做工程数据转换,如何选择?
经验分享
啄缘之间10 小时前
1.【SVA】什么是SVA?
经验分享·学习·测试用例·verilog·sva
天竺鼠不该去劝架10 小时前
企业级智能体怎么选?8 大评估维度,Ki‑AgentS/Copilot Studio/ServiceNow/Coze/Dify 横评
经验分享
FLJwu10 小时前
整机可靠性测试实战 03:防水密封可靠性|IP67/IP68 结构设计、密封胶圈选型与泡水测试量产翻车整改
经验分享·数码相机·相机
我是章汕呐10 小时前
地级市能源消耗量及消耗强度数据【2006-2023年】平衡面板
人工智能·经验分享·算法·回归