# pwn

## Challenges

<figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2F3Yg6gvlfSDxz53TUZXEf%2Fimage.png?alt=media&#x26;token=fa92b179-d2a1-4cc7-b0ea-1ade1e74ad25" alt=""><figcaption></figcaption></figure>

### Index

<figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2FmYFQsoMY94fiNKgdjcH6%2Fimage.png?alt=media&#x26;token=5c7508bb-0d20-4162-87e1-45b50ff45af1" alt=""><figcaption></figcaption></figure>

> I literally hand you the flag, just exploit it already!
>
> * [index.zip](https://storage.googleapis.com/scriptctf_challenges/Pwn/Index/index.zip)

```bash
❯ unzip -l index.zip
Archive:  index.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    16632  2025-08-01 09:44   index
   225600  2025-08-01 12:25   ld-linux-x86-64.so.2
  2003408  2025-08-01 12:25   libc.so.6
---------                     -------
  2245640                     3 files
```

* Load up to [dogbolt](https://dogbolt.org/), or `objdump`
* We could see this

  <figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2Fi5uRO2SMID48vBaQQIKu%2Fimage.png?alt=media&#x26;token=f16a0eb8-5631-439f-b113-0ae19e998979" alt=""><figcaption></figcaption></figure>
* cmp $0x539 compares the user input with 0x539 in hex it is `1337` in decimal
* `je 150e` if they're equal — confirmed with decompiler

<figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2FpHcl9DbumnDLrmpCt7ih%2Fimage.png?alt=media&#x26;token=f7fc42f2-57f2-4f8f-816b-57cba4cb22e1" alt=""><figcaption></figcaption></figure>

* 1337 will triggers a secret fucntion that open `flag.txt`
* We go to `LABEL_401448`
* Or the menu() to be exact

  <figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2FSSL2rIwVTGiqufMqBgEg%2Fimage.png?alt=media&#x26;token=f45f5dc1-107e-4574-89b7-5313185e6a85" alt=""><figcaption></figcaption></figure>
* Now, we need option 2 because `read_data` can read from any memory location without bounds checking
* The flag address is `0x40a0`

  <figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2Fp9MbrfyVq8NzKJjmTPPf%2Fimage.png?alt=media&#x26;token=efc8aaeb-f5f6-461d-92f5-de502c6d848c" alt=""><figcaption></figcaption></figure>
* we also know nums array is at `0x4060`
* ```
  12c3:	48 8d 15 96 2d 00 00 	lea    0x2d96(%rip),%rdx        # 4060 <nums>
  ```
* Finally the calculation is `nums_base + (index * 8)`

  <figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2F2jyEG8bBQowUA3CeAgT7%2Fimage.png?alt=media&#x26;token=7c859efe-0e46-4730-bde0-b67d1482d636" alt=""><figcaption></figcaption></figure>
* `Flag address - nums address = 0x40a0 - 0x4060 = 0x40 = 64 bytes` \ `64 bytes ÷ 8 bytes per index = 8`
* Final exploit

<figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2F7FwINkNSgunzD4h8bJau%2Fimage.png?alt=media&#x26;token=0e1cf535-bc80-48b6-9401-c4fffba92b45" alt=""><figcaption></figcaption></figure>

* <mark style="color:blue;">`scriptCTF{4rra4y_00B_unl0ck3d_0aed67c7e137`</mark>

### Index-2

<figure><img src="https://2268275695-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUrHD5lu5pQjrB9B8IR6W%2Fuploads%2FlUMJsKB9gqX6nosmuYZL%2Fimage.png?alt=media&#x26;token=321a166f-e57e-4918-bffa-a5f54e86bbf3" alt=""><figcaption></figcaption></figure>

> This time, you get the file pointer, not the flag itself.
>
> * [index-2.zip](https://storage.googleapis.com/scriptctf_challenges/Pwn/Index2/index-2.zip)

```bash
❯ unzip -l index-2.zip
Archive:  index-2.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    16608  2025-08-01 09:47   index-2
   225600  2025-08-01 12:23   ld-linux-x86-64.so.2
  2003408  2025-08-01 12:23   libc.so.6
---------                     -------
  2245616                     3 files
```

{% hint style="warning" %}
tbd, will write later
{% endhint %}
