> For the complete documentation index, see [llms.txt](https://kunalwalavalkar.gitbook.io/write-ups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kunalwalavalkar.gitbook.io/write-ups/portswigger-labs/server-side-topics/sql-injection/sql-injection-union-attack-determining-the-number-of-columns-returned-by-the-query.md).

# SQL injection UNION attack, determining the number of columns returned by the query

https\://portswigger.net/web-security/sql-injection/union-attacks/lab-determine-number-of-columns

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2F6s73uNefMblJgPEl8rvo%2F1.png?alt=media&amp;token=e4a1c3a7-7230-4a01-ad77-f387dae41f90" alt=""><figcaption></figcaption></figure>

Let's filter for `Accessories`.

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2Fhkg3URrr3j163Dzeaj3H%2F2.png?alt=media&amp;token=0cb5d38d-9d4e-4fc6-ba80-7744b7ada171" alt=""><figcaption></figcaption></figure>

Since we are proxying the traffic through Burp Suite, we can go to the `Proxy > HTTP History` tab to view this request.

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2FX5VVLJt21ezqQ8UzBeXx%2F3.png?alt=media&amp;token=1d3822e8-312e-4d66-a392-9025434635d9" alt=""><figcaption></figcaption></figure>

Let's forward this request to the `Repeater` for further modification.

Once in the `Repeater`, let's set the `category` parameter to the following:

```
UNION SELECT NULL--
```

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2Fwkao917c2JO0DmCexBCU%2F4.png?alt=media&amp;token=a2e09690-c75d-42d3-9a3b-53b07b965c07" alt=""><figcaption></figcaption></figure>

Since the application returns an error, we know that the number of columns in the current query is more than 1.

Let's try for two columns:

```
UNION SELECT NULL,NULL--
```

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2FvO9krpnZCv4e4ylmVaCp%2F5.png?alt=media&amp;token=771e80a6-8c97-440a-a891-809e733bf06e" alt=""><figcaption></figcaption></figure>

The application again returns an error.

Let's try for three columns:

```
UNION SELECT NULL,NULL,NULL--
```

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2FQYcL3EsAIVRN5jaaIK1i%2F6.png?alt=media&amp;token=3e9b9836-d878-4b31-9ff6-e6d818656511" alt=""><figcaption></figcaption></figure>

The application no longer throws an error which means that there are 3 columns in the current query.

We have solved the lab.

<figure><img src="https://1586847736-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtSZ40gLWhBDTzPEgHsVB%2Fuploads%2Fbkeyk9hkii4PWA9v6QiA%2F7.png?alt=media&amp;token=f0a52c65-bc87-4f76-a77e-253a793f8107" alt=""><figcaption></figcaption></figure>
