Showing posts with label gdb. Show all posts
Showing posts with label gdb. Show all posts

Wednesday, October 13, 2021

Analyzing Apache HTTP Server Information Disclosure Vulnerability - CVE-2021-42013

It was found that the fix for CVE-2021-41773 in Apache HTTP Server 2.4.50 was insufficient. An attacker could use a path traversal attack to map URLs to files outside the directories configured by Alias-like directives. If files outside of these directories are not protected by the usual default configuration "require all denied", these requests can succeed. If CGI scripts are also enabled for these aliased paths, this could allow for remote code execution. 

This issue only affects Apache 2.4.49 and Apache 2.4.50 and not earlier versions. 

To address CVE-2021-41773 the following patch was added.

As you can see the code handles exploit that looks like - "/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd". 

But attackers found ways to bypass this patch and came up with the following uri - "/cgi-bin/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/%%32%65%%32%65/etc/passwd".

When the URL enters the vulnerable function ap_normalize_path it looks like below,

After normalizing the URL the path looked like below,
The code then enters unescape_url which further normalizes path.
Looking at the function's code we can understand it decodes percent encoded characters to ascii version.
And half way during the function execution we can take a look at the memory and see the percent encoded characters getting replaced to their respective ascii characters.
The parsed uri now becomes.
Later the absolute path is built based on the request path and the path to the file is built. After concatenating the document root with the request path the file path becomes like,
The path is then further resolved based on directory traversal and becomes,
This is the new path where the file gets served/read from.

Sunday, July 26, 2020

Break On x86 Syscalls from Pintool

"Pin is a tool for the instrumentation of programs. It supports the Android*, Linux*, OS X* and Windows* operating systems and executables for the IA-32, Intel(R) 64 and Intel(R) Many Integrated Core architectures. Pin allows a tool to insert arbitrary code (written in C or C++) in arbitrary places in the executable. The code is added dynamically while the executable is running. This also makes it possible to attach Pin to an already running process" (https://software.intel.com/sites/landingpage/pintool/docs/81205/Pin/html/)

Pin has an API - "Pin_ApplicationBreakPoint" that can be used to stop execution in an application debugger as though a breakpoint was hit. This API can be made use to call an application debugger wherever & whenever we wish for it. The most common use case would obviously be to call the debugger at a specific place of interest. For the sake of this blog let us use this API to call the debugger at a specific syscall.

Well there's more easier way to break on a specific syscall under GDB using the "catch syscall <syscall name/number>" etc etc, but this blog is to understand the Pin's API, so let us stick to this easy task :)

The steps would be as follow,
  1. During instrumentation find whether a instruction that is to be executed is a syscall
  2. If it is a syscall instruction insert a call to get the syscall number and set a global flag
  3. Insert another call in the same instruction to see if we need to send a SIGTRAP to GDB if the syscall is of our interest
The below recorded demo video illustrates how Pin is able to instruct GDB to break on a specific syscall number - 120 which belongs to the clone syscall.


The ideal use case for the above API would be during break into the application during complex conditions and during that you might require a full blown debugger to proceed further.