pivot_root from within the set_cmnd_path function. Finding this call is straightforward:
Output without types
The above rule annotates the first call topivot_root. For a vulnerable binary, its output is as following:
int set_cmnd_path(struct sudoers_context *ctx, const char *runchroot), without a type library this has little effect as VulHunt doesn’t know anything about the types used by this function such as struct sudoers_context. As a result, we see things like param1 + <offset>, which is not ideal. To fix this and provide a better output, we use type libraries.
Creating type libraries
Creating a type library involves three main steps:- Creating one or more C header files containing the types used by the functions of interest alongside with their prototypes.
- Building these header files into binary format, which effectively creates the type library.
- Loading the type library from the rule using the
typesfield.
sudo.h
struct sudoers_context.
Resolving dependencies
Luckily for us, all other types are defined in sudoers.h and we can just copy their definitions from there. Also, we provide basic types from the C Library such asstruct timespec. To use them, you just need to #include our libc.h.
We also added a #ifndef directive to make sure this type library is only defined once. The final version of the C header file for this type library is as follows:
sudo.h
Building a type library
VulHunt is shipped with a type library utility calledbias-tutil, which is bundled with the VulHunt installation. Note that bias-tutil depends on Clang/LLVM, and requires it be installed and available at runtime.
To build a type library, use the build subcommand:
sudo.bin, which is our type library. You can check if the type is correctly defined in the type library with the query subcommand. For example, the command
sudoers_context type:
query subcommand, see bias-tutil query --help.
Applying the type library
It’s time to apply the type library in our rule. We just need to add thetypes field and set its value to the C header file we created earlier. VulHunt will automatically load the binary type library as long as it is in the correct directory. The final rule is as follows:
In our example rule,typesis set tosudo/v1.9.17/sudo.h, meaning there must be a$BIAS_DATA/platforms/posix/types/sudo/v1.9.17directory containing bothsudo.handsudo.binready to be used by our rule.
Output with types
After loading a type library, the output looks much better:param1 became ctx, which is a variable of sudoers_context type. Its fields are also correctly typed.
As a final note, keep in mind type libraries do not only visually improve the output. They also help when you need to perform advanced source code pattern matching over the decompiled code.