> 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-phpreg.md).

# \[Dreamhack] PHPreg

#### 문제 링크

<https://dreamhack.io/wargame/challenges/873>

[phpregDescription php로 작성된 페이지입니다. 알맞은 Nickname과 Password를 입력하면 Step 2로 넘어갈 수 있습니다. Step 2에서 system() 함수를 이용하여 플래그를 획득하세요. 플래그는 ../dream/flag.txt에 위치합니dreamhack.io](https://dreamhack.io/wargame/challenges/873)

&#x20;

#### 문제

<figure><img src="https://blog.kakaocdn.net/dna/eq1YRe/btsD3cnX0tP/AAAAAAAAAAAAAAAAAAAAAJ3HiagXuB8EiVaqHkXzaDh0LOMpY7llp-MzBdevEgsj/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=mpeDkYyrZEczljEU1jTnnBKQfo8%3D" alt="" height="495" width="731"><figcaption></figcaption></figure>

&#x20;

#### 풀이

<figure><img src="https://blog.kakaocdn.net/dna/cdhh98/btsD3LKa91s/AAAAAAAAAAAAAAAAAAAAAGjpSkc2ELhd25IPw-i4mfnSIK5c5w53J74nMHEOYcdA/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=Mod%2Bod2%2B15AmudmGnyFNw6ExaaQ%3D" alt="" height="612" width="1207"><figcaption></figcaption></figure>

주어진 서버에 처음 접속하면 이런 화면이 나온다. 이런 화면으로는 할 수 있는게 없으니까 문제에서 주어진 PHP 코드를 살펴보도록 한다.

<figure><img src="https://blog.kakaocdn.net/dna/csG8oS/btsD5wMoBPW/AAAAAAAAAAAAAAAAAAAAAC-UU_JM5Ccvb1YjibqA7KkUQlM-6W8xH4OpaPWKlaTQ/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=J9iQHw%2F7DX9k8Eta5Ht7oXGwNH4%3D" alt="" height="508" width="1317"><figcaption></figcaption></figure>

마지막 부분의 코드를 참고하면, \
name이 dnyang0310이고, PW가 d4y0r50ng+1+13이면 step2로 이동할 수 있다고 되어있다는 것을 확인할 수 있다. \
그 윗부분의 else문을 확인해보면, name의 nyang부분이 필터링 되어있고, pw문자열이 필터링 되어있음을 파악할 수 있다.\
따라서 name에서 필터링된 nyang부분을 삽입해주어 name에는&#x20;

```
dnnyangnyang0310
```

을 삽입해주고, \
PW에는 정규표현식을 통해 필터링된 값을 우회하면 되는데, 위에서 사용된 필터링은 아래와 같다.&#x20;

1\. \d\*: 0개 이상의 숫자\
2\. \\@: 문자 "@"\
3\. \d{2,3}: 2개 또는 3개의 숫자\
4\. (31)+: 31이 1회 이상 반복\
5\. \[^0-8]: 0과 8 사이의 숫자를 제외한 문자\
6\. \\!: 문자 "!"

```
1@123319!+1+13
```

를 넣어준다. (0개 이상의 숫자 그리고 2개 또는 3개의 숫자라고 했으므로 1\@123이 아니어도 다른 문자를 넣어도 통과할 것 같다.)&#x20;

<figure><img src="https://blog.kakaocdn.net/dna/Xf2EQ/btsD3mxeIbO/AAAAAAAAAAAAAAAAAAAAAO8gKt44Pkz86pIHQLRljOpl4d8gc84bSwk7hZXHJvYl/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=wmx5BImtuvL0i7LmNdMdnrwVJUA%3D" alt="" height="387" width="601"><figcaption></figcaption></figure>

<figure><img src="https://blog.kakaocdn.net/dna/bXSAuE/btsD1aYEb5h/AAAAAAAAAAAAAAAAAAAAAB8OdItxEGwpW3oMlsSt0e6woiPwQ5JuDZEcEglp0M3p/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=VQo8vx77A%2BIJuT5DXwJcuODfuz0%3D" alt="" height="418" width="433"><figcaption></figcaption></figure>

<figure><img src="https://blog.kakaocdn.net/dna/DO8Xz/btsD08sZ9TB/AAAAAAAAAAAAAAAAAAAAAHiigw_kPCz16R0Y03XhyedD-PN061Dfrncm4xRqRT8h/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=98wFhpN%2BoNTMiWFbsFthk213zeQ%3D" alt="" height="222" width="326"><figcaption></figcaption></figure>

위의 PHP 코드를 해석해야 STEP2를 해결할 수 있는데, command 필터링이 되었다는 것을 이 코드 주석에서 확인할 수 있다. 따라서, 플래그 명령어를 우회해서 작성해주어야 하는데&#x20;

```
cat ../dream/flag.txt
```

를

```
cat ../dream/f*.txt
```

와 같이 우회해서 작성한 후 커맨드 창에 입력을 해주면 플래그 값이 도출된다.

<figure><img src="https://blog.kakaocdn.net/dna/bwZJeJ/btsD4VeqNNX/AAAAAAAAAAAAAAAAAAAAAPpSDm61ohxEuxhLslGBnIOFrTOoFhgFgzb82QlW74LP/img.jpg?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=pISunIRizwfhXUeMZNhoDtcJqBI%3D" alt="" height="397" width="415"><figcaption></figcaption></figure>

<figure><img src="https://blog.kakaocdn.net/dna/CZTyR/btsD3jN39ZP/AAAAAAAAAAAAAAAAAAAAAI6Z640Rc-cM0zqRUW2RaBQqppLOewfKxoaOkJO1pmP8/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=8qK3O%2BF1xbvFj4Lv5cWswG1wz0c%3D" alt="" height="97" width="1165"><figcaption><p>플래그 값</p></figcaption></figure>


---

# 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-phpreg.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.
