> 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/lord-of-sql-injection/lord-of-sqlinjection-gremlin.md).

# \[Lord Of SQLInjection] gremlin

<figure><img src="https://blog.kakaocdn.net/dna/uaYEA/btsMAZgP9a5/AAAAAAAAAAAAAAAAAAAAAAnv3bpP89pa_VO4dB4D6lKvC9bwZZ4OugVpe5ITqRY2/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=P8POLhxx0cGJtWYFSZm5IdrZ6eI%3D" alt="" height="216" width="870"><figcaption></figcaption></figure>

문제 화면을 열면 바로 이런 코드가 냅다 주어진다.

해당 코드를 해석해보면

```
$query = "select id from prob_gremlin where id='{$_GET[id]}' and pw='{$_GET[pw]}'";
```

* id와 pw가 코드 내에서 필터링 되고 있긴 하나 if 문 앞쪽의 정규식 /prob|\_|\\.|\\(\\)/i만을 막고 있다.
* ‘, OR, AND, — 등은 막지 않는 형식인 것을 확인 할 수 있다.

```
if(preg_match('/prob|_|\\.|\\(\\)/i', $_GET[id])) exit("No Hack ~_~");
if(preg_match('/prob|_|\\.|\\(\\)/i', $_GET[pw])) exit("No Hack ~_~");
```

* prob, \_, ., () 를 포함한 문자열은 필터링이 될 수 있다는 것을 확인할 수 있다.

→ 쉽게 공략할 수 있는 키워드들은 막아 두었지만, id와 pw를 웹사이트에서 GET형식으로 입력을 받아서 쿼리를 전송하고, 쿼리에 입력된 id 값이 있다면 gremlin 함수가 실행이 되는 형태로 웹사이트가 동작하는 것을 알 수 있다.

→ SQL Injection은 무조건 같게 만드는 형식으로 쿼리문을 실행한다는 점을 이용해서

```
<https://los.rubiya.kr/chall/gremlin_280c5552de8b681110e9287421b834fd.php?id=admin'OR'1=1>'%23
```

을 도메인값에 전달한다. 이때,

뒤의 쿼리문이 URI 인코딩에 의해 전송되기에 실제로 브라우저 접속하면 주소창에 인코딩된 주소값이 입력될 것이다.

<figure><img src="https://blog.kakaocdn.net/dna/cCP9Ct/btsMA4oV0AZ/AAAAAAAAAAAAAAAAAAAAAI_U9TwoxgSULz829poh7A5jep1X3buY5RJ8U8H0VVOB/img.png?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&#x26;expires=1782831599&#x26;allow_ip=&#x26;allow_referer=&#x26;signature=BUy5jfH7X0uzAyNyQX6SRxXC0%2Fo%3D" alt="" height="699" width="1153"><figcaption></figcaption></figure>

그럼 이런 창이 뜨면서 문제를 해결할 수 있다.

<br>


---

# 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/lord-of-sql-injection/lord-of-sqlinjection-gremlin.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.
