Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make unsorted bin attack great again! #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaherAzzouzi
Copy link

Corrupting the bk of a freed unsorted bin attack can be exploited to gain shell or any other security impact.
The technique was found when auditing GlibC 2.32 source code, but it's working against GlibC 2.34 too.

…ted bin chunk, can lead to an exploitable condition.
@Kyle-Kyle
Copy link
Contributor

Kyle-Kyle commented Oct 19, 2021

If I understand correctly, this technique requires known heap addresses (fake chunk and p) and a target address (where to overwrite). In the demo attack, it uses out-of-bound access to achieve chunk overlapping. In addition, this attack can work in UAF and potentially also double-free scenarios. It does not only do chunk overlapping, it can also lead to arbitrary allocation.

Unfortunately, this attack is not the unsorted bin attack that got killed in glibc-2.29. unsorted bin attack only requires a target address. It can overwrite the value at the target address without knowing the heap address. That's what makes it powerful.

In fact, what this attack wants to achieve is to chain a fake chunk into the unsorted bin list, which is extremely hard without knowing heap addresses after the patch. But with a heap leak, it is easy to achieve once you know the goal is to chain a chunk into unsorted bin list.

I'd suggest you see whether you can achieve the same goal without heap leak. You may achieve it through partial overwrite and reuse the heap values left on heap like how we exploit poisonous_null_byte.

@MaherAzzouzi
Copy link
Author

MaherAzzouzi commented Oct 19, 2021 via email

@Kyle-Kyle
Copy link
Contributor

Kyle-Kyle commented Oct 20, 2021

Good job on finding this technique independently!

However, this technique is not new; it has been extensively used in current techniques. For example, the same attack is used in house_of_einherjar, a similar idea is used in poison_null_byte (not in unsorted bin but in large bin).

Although it is not new, I think this technique should be merged into the repo because it is always good to have atomic techniques that are easy to learn and necessary for mastering compound techniques later.

Before it gets merged, a few changes need to be made though:

  1. change of the name. It shouldn't be called unsorted_bin_attack which is another technique that does not require heap leak. It should be called unsorted bin injection or sort.
  2. line 60 is libc build dependent, which is not good. You can change it to ul heap_base = p & ~(0xfffL)
  3. I don't think line 82 needs the + 0x8

@Kyle-Kyle
Copy link
Contributor

Also, please add more output to the program to allow people understand how it works by only reading its output.
And please explicitly mention what primitives this technique requires (heap leak + another primitive) and how this technique is different from the original unsorted_bin_attack.

Thanks!

@Kyle-Kyle
Copy link
Contributor

Kyle-Kyle commented Oct 20, 2021

@MaherAzzouzi you mentioned that libc leak is required. That is not true. You can have three unsorted bin chunks head->A->B->C->head. Now all both fwd and bk pointers in B are heap pointers. You can use overflow to overwrite B's fwd and bk pointers to preserve its fwd pointer and change the bk pointer to a fake chunk X. And then you overwrite C's fwd pointer to X. Now you let X's fwd pointer to be B and X's bk pointer to be C. Now you have head->A->B->X->C->head. You successfully inserted X between B and C without knowing libc address (head)!

@MaherAzzouzi
Copy link
Author

Yeah you're totally right I can insert one in the middle and only use heap leak, but sometimes a one freed chunk is all you have (the case of the challenge I was doing), and many more.
For suggestions 1 and 2 you're right the name can make an ambiguity with the old attack and I will change it, for the third suggestion it need to be + 0x8, else you will have the following error : malloc(): unsorted double linked list corrupted
I will try to add more output to the PoC when I have time.
Thanks for your time, and thanks for reviewing this technique.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants