当前位置:网站首页>bugku----正则匹配,cookies
bugku----正则匹配,cookies
2022-07-17 00:14:00 【jjj34】
bugku----正则匹配
<?php
error_reporting(0);
$zero=$_REQUEST['zero'];
$first=$_REQUEST['first'];
$second=$zero.$first;
if(preg_match_all("/Yeedo|wants|a|girl|friend|or|a|flag/i",$second)){
// /i 表示不匹配大小写
$key=$second;
if(preg_match("/\.\.|flag/",$key)){
//匹配 .. 或者 flag
die("Noooood hacker!");
}else{
$third=$first;
if(preg_match("/\\|\056\160\150\x70/i",$third)){
// \ddd 表示八进制 \xdd 表示十六进制
// \056\160\150\x70 相当于 .php
// \\ 相当于\ , \| 表示匹配 |字符本身
//所以,这句话的意思是 匹配 |.php
$end=substr($third,5); // 从小标为5的开始截取(包含5),第一个字符小标为0
highlight_file(base64_decode($zero).$end);//maybe flag in flag.php
//这句话提示我们,括号里的结果为 flag.php
}
}
}
else{
highlight_file(__FILE__);
}代码中的注释就是思路
base64_decode($zero).$end = flag.php
1. end为third从第五个字符开始截取的部分,并且third匹配到了 |.php 因此,猜测third为 1234|.php,其中1234是为了匹配第一个正则,即girl
所以,end的值为 .php , third = first = girl|.php
base64_decode($zero) = flag
zero = base64_encode(flag) = 'ZmxhZw=='
构造url
/?zero=ZmxhZw==&first=girl|.php成功拿到flag

关键点:在于第三句的正则
/\\|\056\160\150\x70/i
从左往右一次分解
\\ -> \
\| -> |
\056\160\150\x70 ->.php
转化原理: 以\056为例,先将 056进行八进制转十进制,得到46,然后去ascii码表中查第46号字符,就是 '.'
结合整句话 |.php正则的知识点
bugku---cookies欺骗

不知道要干什么,就放到bp里看看

看到那个filename , 很明显的base64加密,拿去解密后得到
确认了是base64加密,因此我们将filename的值改为 index.php 的加密值,尝试读取源码
确定了可以读取源码,尝试修改line的值看看(猜测line控制读哪一行)

得到结论:可以控制line来读取源码
通过不断的改变line值最终的源码为
<?php
error_reporting(0);
$file=base64_decode(isset($_GET['filename']) ? $_GET['filename']:"");
//三位运算符,如果filename有值,就将filename按base64解密后赋给$file,否则将""按base64解密后赋给$file
$line=isset($_GET['line']) ? intval($_GET['line']) : 0;
//同样是三位运算符,如果line有值,就将line的值强制转化为int类型后赋给$line,否则$line=0
if($file=='')
header("location:index.php?line=&filename=a2V5cy50eHQ=");
//如果file为空,从定向到我们第一次看到的页面
$file_list = array(
'0' =>'keys.txt',
'1' =>'index.php',
);//相当于白名单,也就是我们可以访问的文件
if(isset($_COOKIE['margin']) && $_COOKIE['margin']=='margin'){
$file_list[2]='keys.php';
//本题考点2,意思就是在cookie中加一条margin的值,然后keys.php就进入白名单,盲猜flag在白名单里
}
if(in_array($file, $file_list)){
//对白名单进行验证,如果有的话就根据line读取文件
$fa = file($file);
echo $fa[$line];
}
?>这个就不难,思路在注释里
大概就是要求我们去读取keys.php文件,为了能够读取keys.php文件,我们需要给cookie加一条margin的值
注意:keys.php需要先进行base64加密

边栏推荐
- Hash table, bloom filter, distributed consistency hash
- Gdb+vscode for debugging 7 - how to debug when there is a segmentation default/ segment error in the program?
- 各种开发工具
- Engineering compilation: makefile and cmake (I)
- 成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析
- ENVI_IDL:讀取所有OMI產品的NO2柱含量並計算月均值、季均值、年均值+解析
- STL--map容器
- 【Unity编辑器扩展】Unity制作自己的专属的编辑器面板
- ENVI:(2022年最详细的教程)自定义坐标系
- [tools] unity screen drawing line, unity screen drawing Hsj drawing tool
猜你喜欢

Chengxin University envi_ IDL third week class content 1: reading OMI data (HDF5 file) and output + parsing

ENVI:(2022年最详细的教程)自定义坐标系

ENVI_IDL:批量拼接Modis Swath的逐日数据并输出为Geotiff格式

二叉树的遍历

Labelme 的简单用法和界面介绍

第1章-多智能体系统

Gdb+vscode for debugging 3 - vscode and GDB remote debugging

leetcode力扣经典问题——42.接雨水

ENVI_ Idl: average calculation + analysis of MODIS swath products in batches
![[unity development tips] unity packs the EXE on the PC side and compresses and packs it into an EXE file](/img/b1/6ca7164d218c179918bb2497ab5fa3.png)
[unity development tips] unity packs the EXE on the PC side and compresses and packs it into an EXE file
随机推荐
基于蒙特卡洛的强化学习方法【附带代码实现】
【解决方案】win11中本地组策略编辑器(gpedit.msc)打不开
Vmware Tools最新安装教程(RHEL8)
ENVI_ Idl: read the text file and output it in GeoTIFF format + simple mean interpolation
树和堆知识点总结
Build hue environment
Build Ozzie environment
gdb+vscode进行调试3——vscode以及gdb远程调试
Engineering compilation: makefile and cmake (I)
Configure map reduce workflow in oozie
LeetCode:动态规划中的子序列问题
保留两位小数,并向上取值
The code of dsaa related articles in the blog
ENVI_IDL:批量对Modis Swath产品进行均值运算+解析
ENVI:(2022年最详细的教程)自定义坐标系
搭建Spark on yarn环境
【HSJFramework】Unity时间管理TimeManger计时器
Build map reduce development environment
Double Q-Learning理论基础及其代码实现【Pendulum-v0】
Cookie和Session的区别