0x00前言:
昨天剛剛看完小迪老師的sql注入篇的第一章
所以有了新的筆記。
0x01筆記:
sql注入原理: 網站數據傳輸中,接受變量傳遞的值未進行過濾,導致直接帶入數據庫查詢執行的操作。 sql注入對滲透的作用: 獲取數據 sql注入特性: 攻擊方法由數據庫類型決定 攻擊結果由數據庫決定 漏洞代碼: sql.php <?php $id=$_GET['x']; $sql="select * from news where id=$x"; 還沒完 ?> 當我們在網頁執行訪問了: http://127.0.0.1/sql.php?x=1 在數據庫其實是這樣的 $id=1 select * from news where id=1 注入語句 http://127.0.0.1/sql.php?x=1 and 1=1 真 select * from news where id=1 and 1=1 返回正常頁面 http://127.0.0.1/sql.php?x=1 and 1=2 假 select * from news whsere id=1 and 1=2 返回錯誤頁面 and or xor 且 或 非 sql語句中邏輯運算符: and 1=1 真且真=真 or 1=2 真或假=真 and 1=2 真且假=假 sql注入拓展深入部分: sql注入能調用數據庫作的動作(例如:文件讀寫,調用執行等) php一些sql的函數: mysql_connect(); mysql連接函數 mysql_select_db(); 選擇對應數據庫 mysql_query(); mysql執行函數 sql注入產生的必備條件: 1.變量接受 判斷變量是否接受了:打開一個有id的站修改id看看頁面會不會變化,如果變化了就代表變量接受。如果沒變化,就代表變量不接受。 2.帶入數據庫查詢執行 判斷是否帶入數據庫查詢執行:打開一個有id的站修改id看看頁面會不會變化,如果變化了就代表帶入了數據查詢執行。如果沒變化,是沒帶入數據庫查詢執行的也就是說頁面是不會變動的。 3.不存在過濾(可嘗試繞過) 題目: 1.請從下面站點地址選擇可能存在注入的選項(BCD) 1. www.dikesec.com/news.php 2. www.dikesec.com/news.php?id=1 3. www.dikesec.com/news.php?id=1&page=2 4. www.dikesec.com/login.php 注入代碼前面必須空一個格 2.參數page存在注入,請問下面注入測試正確的是(AC) A.www.dikesec.com/news.php?id=1&page=1 and 1=1 B. www.dikesec.com/news.php?page=1&id=1 and 1=1 C. www.dikesec.com/news.php?page=1 and 1=1 &id=1 www.dikesec.com/news.php?page=1&id=1 如果page是注入點 就要在page后面空一格加注入代碼,而不是在后面加 在我們放入sqlmap進行sql掃描的的時候必須理清楚哪里是注入點,如果page是注入點的話我們得這樣 www.dikesec.com/news.php?id=1&page=1 這樣就可以放到工具里掃了 例子: http://www.gdgy33.com/page.php?id=150&aid=3&bid=1 假設id存在注入我們得移到后面去 變成這樣子 http://www.gdgy33.com/page.php?bid=1&aid=3&id=150 不會影響頁面的 post注入: 假設有個表單讓你進行注入。因為表單的條件方式都是POST。在表單里輸入惡意代碼也會產生注入點 cookie注入: 把惡意代碼帶到cookie后面。
0x02初步:
今天是我們學習sql注入的第一天,就先寫判斷注入的腳本吧。后面慢慢加上去
import requests
import socket
import time
logo="""
___====-_ _-====___
_--^^^#####// \\#####^^^--_
_-^##########// ( ) \\##########^-_
-############// |\^^/| \\############-
_/############// (@::@) \\############\_
/#############(( \\// ))#############\
-###############\\ (oo) //###############-
-#################\\ / VV \ //#################-
-###################\\/ \//###################-
_#/|##########/\######( /\ )######/\##########|\#_
|/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \|
` |/ V V ` V \#\| | | |/#/ V ' V V \| '
` ` ` ` / | | | | \ ' ' ' '
( | | | | )
__\ | | | | /__
(vvv(VVV)(VVV)vvv)
"""
print(logo)
def sql():
global url
url=input('[^]Please enter the URL that needs test injection:').lower()
if url !=None:
time.sleep(0.5)
header={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'}
print('[1]GET')
print('[2]POST')
lwd=input('[^]Please enter what kind of method you want to ask for:')
if lwd=="1":
r=requests.get(url,header)
status=r.status_code
if status == 200:
print('\033[1;32;40m')
print('[^]Link stability')
print('\033[0m')
else:
print('\033[1;31;40m')
print('[~]State code',status)
print('[^]Response code')
print('\033[0m')
exit()
elif lwd=="2":
r=requests.post(url,header)
status=r.status_code
if status == 200:
print('\033[1;32;40m')
print('[^]Link stability')
print('\033[0m')
else:
print('\033[1;31;40m')
print('[~]State code', status)
print('[^]Response code')
print('\033[0m')
exit()
else:
print('[~]Not Found')
exit()
sql()
def zhuru():
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'}
url1=url+'%20and%201=1'
url2=url+'%20and%201=2'
zhusx=requests.get(url,headers).content
zhus=requests.get(url1,headers).content
zhuss=requests.get(url2,headers).content
if zhusx == zhus and zhusx !=zhuss:
print('[^]Discovery of injection point')
else:
print('[~]No injection point was found')
exit()
zhuru()
運行截圖: