> For the complete documentation index, see [llms.txt](https://ir0nstone.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ir0nstone.gitbook.io/notes/writeups/hack-the-box/challenges/web/sanitize.md).

# Sanitize

## Analysis

First we're met with a signin form:

![](/files/-MM6spSm54IYMXI_s_dQ)

Let's try some default creds, `admin` and `admin`.

![The Query](/files/-MK9MLlvNS0vMd9OsNue)

Below, the query run on the database is shown; this seems like a clear example of **SQL injection**.

## Exploitation

Ultimately, we want to try and log in as a user. To do this, we can try to inject our own SQL.

We know the payload looks like the following:

```sql
select * from users where username = '<username>' AND password = '<password>';
```

We want to trick this into always returning a user, and to do this we'll inject a clause that's **always** true, such as `1=1`.

```sql
admin' OR 1=1
```

That will make the query equal to the following:

```sql
select * from users where username = 'admin' OR 1=1 AND password = 'password';
```

So here, it'll compare the `username` to `admin`, and if it's not the same the check will **still** pass because `1=1`. However, there's a small issue with the `password` still being wrong. To bypass *this* check, we'll make everything after our injection a **comment** so that the databse ignores it:

```sql
admin' OR 1=1;--
```

That would make the query be:

```sql
select * from users where username = 'admin' OR 1=1;-- AND password = 'password';
```

As you can see, the `username` will always be correct due to the `1=1` and the password check is commented out! Let's try it.

![](/files/-MKzGHSgDLFOusS7Hq7F)

We still have to input a password because some javascript checks to make sure it's there, but we can fill that with any rubbish. And we get the flag!

`HTB{SQL_1nj3ct1ng_my_w4y_0utta_h3r3}`


---

# 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, and the optional `goal` query parameter:

```
GET https://ir0nstone.gitbook.io/notes/writeups/hack-the-box/challenges/web/sanitize.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
