两道CTF Web的题目
1.easyphp
1.1.题目描述
题目首先是一张不存在的图片
查看源码发现只有一句话
<img src="show.php?img=aGludC5qcGc=" width="100%"/>
点开源码中图片的链接,跳转到下面的页面
img 后面的内容很像是 base64 编码,经过解码验证,确实是 base64 编码,还原后是 hint.jpg 。
尝试把 img 后面的参数用 flag.jpg、flag.php、flag 的base64编码代替后访问,并没有获取到有价值内容
直接访问 index.php 或者 show.php 也看不到任何东西,所以看看能不能利用 img 这个参数读取两个php源码
index.php 的 base64编码为 aW5kZXgucGhw
show.php 的 base64 编码为 c2hvdy5waHA=
经过尝试后,这时通过源码已经可以读取到内容,内容分别如下
index.php
<?php
require_once('hint.php');
$x = new hint();
isset($_GET['class']) && $g = $_GET['class'];
if (!empty($g)) {
$x = unserialize($g);
echo $x;
}
?>
<img src="show.php?img=aGludC5qcGc=" width="100%"/>
show.php
<?php
$f = $_GET['img'];
if (!empty($f)) {
$f = base64_decode($f);
if (stripos($f,'..')===FALSE && stripos($f,'/')===FALSE && stripos($f,'\\')===FALSE
&& stripos($f,'flag')===FALSE) {
readfile($f);
} else {
echo "File not found!";
}
}
?>
从 index.php 的源码里看到还有个 hint.php,用同样的方法读取,内容如下
hint.php 的 base64 编码为 aGludC5waHA=
<?php
error_reporting(0);
//flag is in flag.php
class hint{
public $file='';
function __destruct(){
if(!empty($this->file)) {
if(strchr($this-> file,"\\")===false && strchr($this->file, '/')===false)
show_source(dirname (__FILE__).'/'.$this ->file);
else die('Wrong filename.');
}}
function __wakeup(){ $this-> file='index.php'; }
public function __toString(){return '' ;}}
?>
1.2.代码审计
hint.php 里面告诉我们 flag 在 flag.php中,所以我们要尝试去读取到这个 php 文件
show.php 里面用 stripos 限制了我们读取的内容,我们不能通过 show.php 的方式来读取到 flag.php
hint 里面定义了一个 hint 类,这个类有个 show_source(dirname (__FILE__).'/'.$this ->file); 方法,可以读取我们的 php 文件
而在 index.php 里面用到了 unserialize() 函数,用来反序列化一个 hint 对象,我们可以尝试使用反序列化的方式来读取 flag.php
1.3.Payload构造
将 hint.php 复制到本地,然后添加下面几行代码,通过网页取得序列化后的字符串
$x=new hint();
$x->file="flag.php";
echo serialize($x);

O:4:"hint":1:{s:4:"file";s:8:"flag.php";}
序列化字符串的含义可以参考:https://www.cnblogs.com/dogecheng/p/11652022.html
根据 index.php 的源码,我们把这个字符串赋值给 class 就好了,但是并没有取得 flag
在网上查询了一些资料后得知,通过 unserialize 反序列化之后,还会调用 __wakeup() 方法,它会把 file 设为 index.php,所以读取的并不是 flag.php
我们需要绕过 __wakeup() 函数,但是绕过方法很简单。当序列化字符串中,表示对象属性个数的值大于实际属性个数时,那么就会跳过wakeup方法的执行。
我们原来的序列化字符串为:
O:4:"hint":1:{s:4:"file";s:8:"flag.php";}
我们只需要把 1 改成比它大的数字即可
O:4:"hint"::{s:4:"file";s:8:"flag.php";}
这时候重新提交请求就能获得 flag 了

2.calculate
2.1.题目描述
题目如下

要求我们回答10道计算题。经过测试,每道题要在3秒内答对,答错或超时清零回答正确的问题个数。而且答题间隔要在1秒以上。
页面源码如下,计算表达式 都在 div 中
<h1>calculate</h1> <p>Answer the questions for 10 times and you can get flag.</p>
<p> You Have answered 0銆€questions;</p> <form action="" method="post">
<div style="display:inline;color:#499E86">6</div><div style="display:inline;color:#BC2109">1</div><div style="display:inline;color:#E20AAD">5</div><div style="display:inline;color:#AE2893">+</div><div style="display:inline;color:#A3A7DA">9</div><div style="display:inline;color:#72311C">9</div><div style="display:inline;color:#7D99E9">7</div><div style="display:inline;color:#3DB475">+</div><div style="display:inline;color:#2144AE">6</div><div style="display:inline;color:#8523C0">1</div><div style="display:inline;color:#D42154">5</div><div style="display:inline;color:#DD166F">*</div><div style="display:inline;color:#0ADBF4">9</div><div style="display:inline;color:#116660">9</div><div style="display:inline;color:#4F6723">7</div><div style="display:inline;color:#7F7A0D">=</div>
<input type="text" name="ans">
<input type="submit" value="send!">
</form>
2.2.脚本编写
一开始用 python 的 requests 库来做,没有成功,自己的代码估计有小BUG,后来改用 selenium 来做就成功了 ,代码如下:
from selenium import webdriver
from bs4 import BeautifulSoup
import time driver=webdriver.Firefox()
driver.get("http://****:13002/") def submit(driver):
# 获取源码
source = driver.page_source
# BeautifulSoup解析
soup = BeautifulSoup(source, "lxml")
all_div = soup.find_all(name="div") # 获取表达式
s = ""
for i in all_div:
s = s + i.contents[0]
# 去掉等号
s = s[:-1]
print(s) # 计算
res = eval(s) # 填入答案
element = driver.find_element_by_name("ans")
element.send_keys(res) # 等待 1.1 秒
time.sleep(1.1) # 提交答案
driver.find_element_by_xpath("/html/body/form/input[2]").click()
print("click") for i in range(10):
submit(driver)
回答 10 次后在页面上就会出现 flag
两道CTF Web的题目的更多相关文章
- leetcode简单题目两道(2)
Problem Given an integer, write a function to determine if it is a power of three. Follow up: Could ...
- 2019CISCN华南线下两道web复现
原帖地址 : https://xz.aliyun.com/t/5558 2019CISCN华南线下的两个简单 web 部分题目下载地址,有的不完整 : 点我点我 web 1 考点 : 无参函数的 RC ...
- 你所不知道的库存超限做法 服务器一般达到多少qps比较好[转] JAVA格物致知基础篇:你所不知道的返回码 深入了解EntityFramework Core 2.1延迟加载(Lazy Loading) EntityFramework 6.x和EntityFramework Core关系映射中导航属性必须是public? 藏在正则表达式里的陷阱 两道面试题,带你解析Java类加载机制
你所不知道的库存超限做法 在互联网企业中,限购的做法,多种多样,有的别出心裁,有的因循守旧,但是种种做法皆想达到的目的,无外乎几种,商品卖的完,系统抗的住,库存不超限.虽然短短数语,却有着说不完,道不 ...
- ACM/ICPC 之 SPFA范例两道(POJ3268-POJ3259)
两道以SPFA算法求解的最短路问题,比较水,第二题需要掌握如何判断负权值回路. POJ3268-Silver Cow Party //计算正逆最短路径之和的最大值 //Time:32Ms Memory ...
- 两道面试题,带你解析Java类加载机制
文章首发于[博客园-陈树义],点击跳转到原文<两道面试题,带你解析Java类加载机制> 在许多Java面试中,我们经常会看到关于Java类加载机制的考察,例如下面这道题: class Gr ...
- 【转】两道面试题,带你解析Java类加载机制(类初始化方法 和 对象初始化方法)
本文转自 https://www.cnblogs.com/chanshuyi/p/the_java_class_load_mechamism.html 关键语句 我们只知道有一个构造方法,但实际上Ja ...
- 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester
这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
- 穷举(四):POJ上的两道穷举例题POJ 1411和POJ 1753
下面给出两道POJ上的问题,看如何用穷举法解决. [例9]Calling Extraterrestrial Intelligence Again(POJ 1411) Description A mes ...
- 两道人数多,课程少,query多的题
#每天进步一点点# 来两道很相似的题目~ (智商啊智商.....) hihoCoder #1236:Scores (简单的分桶法+bitset) 2015 Beijing Online的最后一题.题目 ...
随机推荐
- New Machine Learning Server for Deep Learning in Nuke(翻译)
最近一直在开发Orchestra Pipeline System,歇两天翻译点文章换换气.这篇文章是无意间看到的,自己从2015年就开始关注机器学习在视效领域的应用了,也曾利用碎片时间做过一些算法移植 ...
- 特殊字符(包括emoji)梳理和UTF8编码解码原理(转)
转自:https://www.jianshu.com/p/57c27d67a8a8 背景知识 emoji表情符号,是20世纪90年代由NTT Docomo栗田穣崇(Shigetaka Kurit)创建 ...
- 28.密码学知识-hash函数-5——2019年12月19日
5. 单向散列函数 "单向散列函数 --- 获取消息的指纹" 在刑事侦查中,侦查员会用到指纹.通过将某个特定人物的指纹与犯罪现场遗留的指纹进行对比,就能够知道该人物与案件是否存在关 ...
- 【leetcode】802. Find Eventual Safe States
题目如下: 解题思路:本题大多数人采用DFS的方法,这里我用的是另一种方法.我的思路是建立一次初始值为空的safe数组,然后遍历graph,找到graph[i]中所有元素都在safe中的元素,把i加入 ...
- FileUtils (从磁盘下载,从网络下载)
public class FileUtils { /** * realPath 磁盘路径 D://project/download/ * urlPath 后半部分路径 具体根据业务需求,例如:WEB- ...
- Comet OJ - Contest #6 D. 另一道树题 并查集 + 思维 + 计数
Code: #include <cstdio> #include <algorithm> #include <cstring> #include <vecto ...
- 在volist中用遍历
$('.InColor').each(function(){ if($(this).val()==1){ $('.absolute').css({"color":"gra ...
- wnmp部署
原文地址: https://www.cnblogs.com/chaooo/p/5462781.html Before:提前规划好的目录结构 1.安装Nginx 到Nginx官网下载最新稳定版 ht ...
- 13 November
[HEOI2015] 定价 BZOJ 4027: 在市场上有很多商品的定价类似于 999 元.4999 元.8999 元这样.它们和 1000 元.5000 元和 9000 元并没有什么本质区别,但是 ...
- 20175214 《Java程序设计》第11周学习总结
20175214 <Java程序设计>第11周学习总结 本周学习任务总结 1.根据<java2实用教程>和蓝墨云学习视频学习第十三章: 2.尝试将课本重点内容用自己的话复述手打 ...