Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save xyqer1/09fe6488a6655776c8c5d33e630a0f2a to your computer and use it in GitHub Desktop.

Select an option

Save xyqer1/09fe6488a6655776c8c5d33e630a0f2a to your computer and use it in GitHub Desktop.

Netgear-R6100-cgiMain-QUERY_STRING-StackOverflow

Vulnerability Details

  • Affected Firmware: V1.0.1.28
  • CVE-ID: CVE-2025-29044
  • Root Cause: By analyzing the webs file in the bin directory, I found that the function main of cgiMain contains a stack overflow vulnerability.
  • Impact: Remote unauthenticated attackers can hijack the program's control flow.

Vendor Information

During my internship at Qi An Xin Tiangong Lab, I discovered a stack overflow vulnerability in the Netgear-R6100 router.

By analyzing the webs file in the bin directory, I found that the function main of cgiMain contains a stack overflow vulnerability.

The stack overflow can be triggered by the QUERY_STRING key value, which leads to a sprintf stack overflow.

image-20250227170457784

It can be seen that there is a stack overflow in the above function. To call this part of the code,in the following function, argv[1] is either not some specific values. Carefully look for the values that meet the condition including -f, and then adopt it. And the environment variable CONTENT_LENGTH should be empty.

image-20250227171014677

How can we simulate a router

Use the following command to simulate with qemu.

sudo chroot ./ ./qemu-mips-static -E QUERY_STRING='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' -g 1234 -L /lib sbin/cgiMain -f

Attack result

image-20250227171424683

Through the above image, it can be seen that we have overflowed to the offset of 0x274. This does not mean that only this much can be overflowed, but rather that there is no limit to the overflow. It is just that this much is sufficient.

image-20250227171737862

Through the above code snippet, the stack space size can be calculated as 0x248, which means we have successfully achieved stack overflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment