Skip to content

Latest commit

 

History

History
74 lines (38 loc) · 3.46 KB

iptables SEGFAULT Hunt.md

File metadata and controls

74 lines (38 loc) · 3.46 KB

So, as shown at Clumsy keyboard a SEGFAULT is triggered when attempting to use iptables without the sufficient privileges. Let's have a look to it!


A quick look on valgrind, shows that iptables trying to pass a NULL Pointer to a function to be used:

image

So gdb was fired up, symbols and sources loaded into path and breakpoints set to those functions

image

Tracing the SEGFAULT

The first breakpoint is hit, the code is about to call xtables_main(...) image


It enters the function and some of the code is displayed, but not all of it... I took the time to review the code to see what it is actually doing:

image

A more handy “trace” of how far we are right now:

image

Continue and hit the next breakpoint, where some of the parameters passed to the function do_commandx are easily displayed:

image image


Continue to the next function, add_entry, shows some code that might seem complicated at first sight, but nevertheless: image

Once reviewed, the interesting code for this function is shown below:

image


The next function, nft_rule_insert is an interesting one, as here is where the last working pieces of code are ran. Keep an eye on rulenum variable, as this is the var that will cause an uninitalized pointer to be passed to the next function.

image

Here, a pointer to a nftnl_rule_list struct called list is created, but never initialized due to the rulenum being 0

image

image

Therefore, a var called new_rule is initialized at line 2139, but the function that fills it, nft_rule_add, returns NULL due to the lack of privileges:

image


And the last function of our breakpointed list arrives:

image

As shown, list_add is called on line 782, trying to dereference a NULL pointer, by accessing its list parameter.

image

And that's it. SEGFAULT you!