> For the complete documentation index, see [llms.txt](https://vida03.gitbook.io/redteam/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vida03.gitbook.io/redteam/web/mysql-case-sensitive-problems.md).

# Mysql Case Sensitive Problems

## Introdução

Ao efetuar comparações no mysql normalmente utilizamos:

```
mysql> SELECT name FROM admins WHERE name = "ghosthk";
+---------+
| name    |
+---------+
| ghosthk |
+---------+
```

Bom, o mysql fez o que pedimos, porém observe esse outro comportamento:

```
mysql> SELECT name FROM admins WHERE name = "ghostHK";
+---------+
| name    |
+---------+
| ghosthk |
+---------+
```

Preste atenção no "HK" em maiúsculo, o mysql retornou o resultado mesmo assim

<figure><img src="/files/GpIoxeYBiNJL6RM3ad9D" alt=""><figcaption></figcaption></figure>

## Bypass Time

Agora vamos observar isso em uma aplicação de teste (vou utilizar o mysqli, porém o mesmo comportamento se aplica na utilização do PDO, pois o erro está no mysql e não nos meios de consulta que utilizamos para se comunicar com o banco de dados):

<figure><img src="/files/VXZGW72l82ZzKmaILUAr" alt=""><figcaption></figcaption></figure>

A aplicação simplesmente verifica se o usuário passado é igual a "ghosthk", se for ele vai exibir "WELCOME ADMIN" caso não ele exibe "YOU NOT IS ADMIN". O que vai acontecer é que irei passar "gHostHK" como usuário e ele irá retornar "WELCOME ADMIN":

<figure><img src="/files/F2yWb9JsOSbeOH6n8iVe" alt=""><figcaption></figcaption></figure>

Agora vamos ver isso em um ambiente mais próximo da realidade (utilizarei uma fortress do HTB):

<figure><img src="/files/pTkIczTT10hspPE5zavl" alt=""><figcaption></figcaption></figure>

A aplicação irá verificar se o usuário solicitado para criar é o igual a "elonmusk", se for igual ele dará erro, se for diferente ele irá criar o usuário, ou seja, podemos criar um usuário "eloNMusk"

<figure><img src="/files/yN3pSDpAaTKjiShkQwtp" alt=""><figcaption></figcaption></figure>

Se o usuário for igual "elonmusk" ele nos deixa acessar a feature de download. Porém repare na comparação, essa condição retornará resultado se criamos um usuário chamado "eloNMusk".

Criei e entrei com o usuário:

<figure><img src="/files/0AHX3mvTh1DCViZxN5J7" alt=""><figcaption></figcaption></figure>

Agora vamos acessar a rota "download":

<figure><img src="/files/lZJJ9Z8pNtLljy1NVcJ2" alt=""><figcaption></figcaption></figure>

Pronto, conseguimos bypassar a verificação!

## Mitigação

E como podemos corrigir? Simples, basta efetuar a query utilizando BINARY, como no exemplo a seguir:

<figure><img src="/files/PCiBTEysH2qqfiw6r1eb" alt=""><figcaption></figcaption></figure>

## Links para correções alternativas

Existem outras formas também, siga o link para exemplos:

{% embed url="<https://stackoverflow.com/questions/4879846/how-to-configure-mysql-to-be-case-sensitive>" %}

{% embed url="<http://i3sistema.com.br/crm/knowledge-base/desativar-case-sensitive-do-mysql-open-suse>" %}

Obrigado por ler até aqui!


---

# 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://vida03.gitbook.io/redteam/web/mysql-case-sensitive-problems.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.
