๐ Introduction
WebSocket
์น ์์ผ์ ๋จ์ผ ์์ฒญ ๋น ์ฐ๊ฒฐํ์ธ HTTP์ ๋จ์ ์ ๋ณด์ํ๊ธฐ ์ํ ํ๋กํ ์ฝ๋ก HTTP ๊ธฐ๋ฐ์ Handshake ๊ณผ์ ๊ณผ ์ดํ TCP/TLS ํต์ ์ ์ด์ฉํ์ฌ ์๋ฒ์ ํด๋ผ์ด์ธํธ๊ฐ ์ง์์ ์ผ๋ก ์์ผ ํต์ ํ ์ ์์ต๋๋ค.
- Stateful ํ ํ๋กํ ์ฝ
- ํฌ๊ฒ Handshake์ Data transfer์ ๊ณผ์ ์ผ๋ก ๋๋จ
๋ง์ ์น ์์ผ์ Data transfer ๋จ๊ณ์์ subprotocol์ ์ฌ์ฉํ์ฌ ํต์ ํฉ๋๋ค. ๋ณธ ๊ณต๊ฒฉ๊ณผ๋ ๋ฌด๊ดํ์ง๋ง ์์๋๋ฉด ์ข์ต๋๋ค. (sub-protocols)
WebSocket handshake
์น ์์ผ์ ์๋์ ์๋ handshake ๊ณผ์ ์ ํตํด ์๋ฒ์ ํด๋ผ์ด์ธํธ๊ฐ ์ฐ๊ฒฐํฉ๋๋ค. ์ดํ์ ๊ธฐ์กด HTTP ํต์ ์์ WebSocket ํต์ ์ผ๋ก Switching ๋ฉ๋๋ค.
WebSocket Connection Smuggling
์น์์ผ์ ์์์ธ HTTP Upgrade Request๊ฐ ์ ์ก๋ ๋ Sec-WebSocket-Version ํค๋ ๋ฑ์ ์๋ชป๋ ๊ฐ์ด ํฌํจ๋ ๊ฒฝ์ฐ ์๋ฌ ์๋ต์ธ 426์ด ๋ฐ์ํฉ๋๋ค. ์ฌ๋ฏธ์๋ ์ ์ ์ด ๋ ํด๋ผ์ด์ธํธ์ ์น ์์ผ ์๋ฒ๋ Connection(wss๋ tls, ws๋ tcp)์ด ๋งบ์ด์ง๊ณ ์ด๋ ์น ์์ผ ํต์ ์ ์ฌ์ฉํ์ง ์์ต๋๋ค.
The |Sec-WebSocket-Version| header field in the client’s handshake includes the version of the WebSocket Protocol with which the client is attempting to communicate. If this version does not match a version understood by the server, the server MUST abort the WebSocket handshake described in this section and instead send an appropriate HTTP error code (such as 426 Upgrade Required) and a |Sec-WebSocket-Version| header field indicating the version(s) the server is capable of understanding.
์ฆ HTTP ์์ฒญ์ ์ฒ๋ฆฌํ ์ ์๋ ํฐ๋์ด ์๊ธด๊ฑฐ๊ณ , ์ฌ์ฉ์๊ฐ Connection close๋ฅผ ํ์ง ์๊ณ ๋ฐ๋ก HTTP ์์ฒญ์ ์ ๋ฌํ๋ฉด, Back-End์ ์๋ ์์ผ ์๋ฒ๊ฐ ์ด๋ฅผ ์ฒ๋ฆฌํ์ฌ ์ฌ์ฉ์์๊ฒ ์ ๋ฌํด์ค๋๋ค. (G/W ๋ฐฉ์์ด๋, Front-End๊ฐ ๋ณ๊ฐ๋ก ์๋ ๋์ผํฉ๋๋ค)
๊ฒฐ๊ตญ ๊ณต๊ฒฉ์๋ ์ด ํฐ๋์ ์ด์ฉํด์ ๋ฐฑ์๋ ์๋ฒ์ ํต์ ํ ์ ์๊ฒ ๋ฉ๋๋ค. ์ด ์์ฒด๋ง์ผ๋ก ๋ฌธ์ ๊ฐ ๋์ง ์์ง๋ง, HTTP ๊ธฐ๋ฐ์ ACL์ด ์๋ ๊ฒฝ์ฐ ์ผ๋ฐ์ ์ธ ์น ์์ฒญ์์ ์ ๊ทผํ์ง ๋ชปํ๋ ๊ฒฝ๋ก์ ์ด tls/tcp ํฐ๋์ ์ด์ฉํ์ฌ ์ ๊ทผํ ์ ์๊ฒ ๋ฉ๋๋ค.
๐ก Offensive techniques
Detect
์ด๋ฅผ ์ฒดํฌํ๊ธฐ ์ํด์ ๋น์ ์์ ์ธ Sec-WebSocket-Version ํค๋๋ฅผ ํฌํจํด์ ์ ์กํ์ฌ Response์ ์ฒ๋ฆฌ ๋ฐฉ์์ ํ์ธํฉ๋๋ค. ๋ณดํต 426 Response๊ฐ ์ค๋ฉด ์ทจ์ฝํ ๊ฐ๋ฅ์ฑ์ด ์กด์ฌํ๋ฉฐ, ์ฌ๊ธฐ์ Socket Smugglingํ์ฌ ๋ค๋ฅธ Resource๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋์ง ์ฒดํฌํด์ผํฉ๋๋ค. ์ด๋ฅผ ์ฝ๊ฒ ํ๊ธฐ ์ํด ๊ฐ๋จํ ๋๊ตฌ๋ฅผ ํ๋ ๋ง๋ค์์ต๋๋ค.
Install websocket-connection-smuggler
|
|
Testing with websocket-conneciton-smuggler
|
|
Set target
|
|
Set SSL
|
|
Set Original Request
|
|
Set smuggled request
|
|
Running sample
|
|
Exploitation
WebSocket Connection Smuggling์ด ํ์ธ๋๋ฉด ๋ด๋ถ ๋ฆฌ์์ค์ ์ต๋ํ ์ ๊ทผํด์ ๋ฐ์ดํฐ๋ฅผ ๋ฝ์์ผํฉ๋๋ค. Smuggle request์ Host header ๋ฑ์ ์์ ํ๋ฉด์ ์ ๊ทผํ ์ ์๋ ๋ฆฌ์์ค๋ฅผ ํ์ธํ์ฌ ์ํฅ๋ ฅ์ ์ฆ๋ช ํฉ๋๋ค.
HTTP
|
|
HTTPS
|
|
๐ก Defensive techniques
๋น ์ ์์ ์ธ Sec-WebSocket-Version
ํค๋๊ฐ ์์ฒญ๋์์ ๋ ์น ์์ผ ์๋ฒ์์ ๋ฌด์ํ๋ฉด ๋ฉ๋๋ค. ๋ณดํต ์ดํ๋ฆฌ์ผ์ด์
/๋ผ์ด๋ธ๋ฌ๋ฆฌ๋จ์์ ํจ์น๊ฐ ๋์์ ๊ฐ๋ฅ์ฑ์ด ๋๊ณ , ๋์๋ค๋ฉด ํจ์น๋ฅผ ์ ์ฉํด์ฃผ์๋ฉด ๋ฉ๋๋ค.
๐น Tools
- https://github.com/hahwul/ws-smuggler
- https://github.com/hahwul/websocket-connection-smuggler
- https://github.com/hahwul/websocket-connection-smuggling-go