BugKu Web(21-25)


前言

bugku刷题,本来想每10道写一篇的,但水平有限,发现到这里题目难度已经有点大了,所以每5道题整合一篇吧…


题目

  1. 秋名山老司机

    1
    登陆可以看到如上提示,然后快速刷新可以看到要求是post提交,键名为value
    2
    这肯定是人工没法完成的,必须写脚本
    py脚本写起来的时候,没有用过eval函数,是真的痛苦,不断字符串处理,条件判断…
    最后还不对,最后看了别人的博客后发现代码即为简短…主要就是eval函数

    import requests
    import re
    url = 'http://123.206.87.240:8002/qiumingshan/'
    s = requests.Session()
    source = s.get(url)
    expression = re.search(r'(\d+[+\-*])+(\d+)', source.text).group()
    result = eval(expression)
    post = {'value': result}
    print(s.post(url, data = post).text)
    

    这道题主要考查的就是脚本的编写,很多时候其实都会遇到要编写脚本
    urllib,requests,re…这些模块都很常用到需要好好熟悉

  2. 速度要快

    3
    题目没给什么信息,查看源码有个提示,但也不懂它在说什么
    4
    这时候抓包看下,神奇的发现了flag…
    5
    这时候base64解码看下
    6
    把得到的值拿去提交发现不对…
    这时候用repeater多go几次发现flag在变…
    现在在根据它前面源码的提示来看,应该是要我们在短时间把得到的flag已post形式传过去
    这时候写个脚本就好了
    最开始用urllib死活不行,后面想了想应该是cookie的问题,然后查了下怎么使用返回的cookie…还是requests方便…
    然后要base64解两遍这个也是坑不参考别人的做法就基本卡死在这里了,毕竟加解密这一块不是特别理解
    7

    import base64
    import http.cookiejar
    from urllib import request,parse
    
    url = 'http://123.206.87.240:8002/web6/'
    
    cjar=http.cookiejar.CookieJar()
    cookie=request.HTTPCookieProcessor(cjar)
    opener=request.build_opener(cookie)
    request.install_opener(opener)
    
    res = request.urlopen(url)
    
    flag = res.headers.get('flag')
    value = (base64.b64decode((base64.b64decode(flag.encode('utf-8')).decode().split(':'))[1].encode('utf-8')))
    value = value.decode()
    
    params = {'margin':value}
    
    data = bytes(parse.urlencode(params), encoding='utf8')
    res2 = request.urlopen(url, data=data)
    print(res2.read().decode('utf-8'))
    
  3. cookie欺骗

    点进去后发现给了一串奇怪的数字,看源码也没有提示,题目名叫cookie欺骗,所以用burp抓下包
    8
    查看cookie也没得到什么提示,但看URL发现有串数字貌似是base64编码
    解码后发现是keys.txt
    9
    尝试访问
    10
    可以看到就是前面页面的那串文字,所以这里应该是文件包含
    这时候尝试来读取下index.php
    11
    结果没有回显…OK,可以看到前面还有一个line参数,应该是控制行数,可以发现带上数字后就有回显了

    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];
    }
    ?>
    

    读取下来就如上面所示,18行,建议还是上脚本吧…
    可以看到cookie那里只有margin == ‘margin’ 才能访问keys.php
    这里要注意的是,URL那里要改成keys.php的base64编码
    12

  4. never never never give up

    13
    拿到题目后发现又是只有一句话,然后发现url中有id=1,很开心的往sql注入方面考虑
    一顿操作发现没有注入点?
    再来检查下源码看下有什么提示
    14
    可以看到提示了一个1p.html
    开心的直接访问,结果跳转到bugku论坛去了…
    发生了重定向,用burp来抓包看
    15
    又能得到提示
    可以看到使用了js的unescape来解码,我们也来解一下
    16
    可以看到后面拿一串还有base64编码
    17
    解了之后发现还有URL编码…
    18
    终于拿到源码…如下

    `php
    “;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 !!!";
    

    }

?>


   OK,看到需要a,b,id三个参数,然后满足各种要求后会返回flag...  
   php不行的我直接尝试了下访问f4l2a3g.txt,结果成功得到flag…(这里其实直接百度了下怎么去绕这规则,结果看到别人说直接访问就OK...)  
   ![19](https://raw.githubusercontent.com/NKcell/BlogPic/master/20190603160903.png)

   > !$_GET[‘id’]并且id==0:令id=%00或者令id=.字符串都可以绕过
   >
   > php认定0e开头的 == 0, php://input 绕过file_get_contents, 星号或问号或.点号绕过正则表达式的匹配
   >
   > payload: http://120.24.86.145:8006/test/hello.php?id=0e123&a=php://input&b=*23456

   这是别人用绕过形式做的提供的payload,但我试了下没有成功... 
   可以参考下 https://blog.csdn.net/qq_34072526/article/details/86946759
   ​                    https://blog.csdn.net/xuchen16/article/details/82783162

   这两篇博客都是用绕过做的

5. Welcome to bugku

   这道题也是进入之后没什么信息,看源码发现有提示
   ![20](https://raw.githubusercontent.com/NKcell/BlogPic/master/20190606085718.png)
   很显然这里是一个代码审计,我们就需要根据它提示来满足要求让器成功包含hint.php  
   这里file_get_contents上面也提到了绕过方法,利用php://input伪协议来做  
   可以看下这篇文章[一谈php://input和php://output](https://blog.csdn.net/qq_27682041/article/details/73326435)  
   但是我用hackbar去传参一直没反应,搞了来好久放弃(这应该就是上道题没能绕过的原因吧)  
   用burp来抓包改吧
   ![21](https://raw.githubusercontent.com/NKcell/BlogPic/master/20190606095639.png)
   可以看到这里返回已经有变化了,方向是对的  
   这时候我们需要再来绕include这里,这里是文件包含要读区php文件,很容易想到另一个伪协议php://filter  
   可以参考:[CTF/CTF练习平台-flag在index里【php://filter的利用】](https://blog.csdn.net/wy_97/article/details/77431111)  
   这样我们就拿到hint.phpbase64加密后的源码
   ![22](https://raw.githubusercontent.com/NKcell/BlogPic/master/20190606101003.png)
   然后我们解密拿到源码
   ![23](https://raw.githubusercontent.com/NKcell/BlogPic/master/20190606101103.png)
   OK,看到这个会想到反序列化,但还缺少源码来审计,这里我们把hint.php改为index.php来获取index.php的源码

   ```php
   <?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 ! ";  
   }  
    -->  

果然我们再password这里看到了unserialize
当然这里有可以读取文件首先我们应该要从简单的地方做起,尝试直接读flag.php
24
可以看到果然不行,这里我们看到password反序列化后有echo password
然后flag这个类的__tostring里有echo file_get_contents
ok利用来构造payload
25
运行得到payload,然后再URL中再加上password就能得到flag了
26
这道题就相对来说有点综合了,考查了两个伪协议,反序列,代码审计


路漫漫其修远兮,吾将上下而求索