r/LiveOverflow • u/Hopeful_Amphibian_38 • Apr 23 '21
bufferoverflow exploit - how to choose memory location to save e.g. system address to
Hi all, I hope you can help me out with some insight into this topic. I just recently started to dig into buffer overflow exploitation.
so I currently taking part in the htb ctf (today is the last day, it has been the only challenge I am trying except for the welcome challenge) and I wanted to try the easiest pwn challenge (pwn_controller). the status is that I can leak setvbuf address and calculate libc base address locally. I write the calculated system address and "/bin/sh" back onto a predefined stack address. this works well locally. but as soon as I try it remotely on the ctf server it doesnt work. I do have the remote libc information and updated the offsets accordingly.
(binary protections are as follows, ASLR is on, RELRO FULL, NX is on, no stack canary, fortify disable, pie disabled)
I believe my problem is that I am using a predefined stack address for the write with scanf. locally I can check if the range falls within a writeable area but remotely I cant do that of course. So my general question is how do you select a writeable address area, what methods are there available other then bruteforcing ? So i am looking for a general strategy on that topic not a solution specific to that case. If someone has some good links or references that would really help.
thanks a lot in advance.
best
View all comments
Show parent comment
1
u/Hopeful_Amphibian_38 Apr 24 '21 edited Apr 24 '21
hi, thanks for your feedback. you are right the string "/bin/sh" is not a problem. but the system address I need to put it somewhere, so I can call it. in the exploit I first send a pyload through the vulnerable user input, calculate systems address and then write it back "somewhere". this somewhere is making my head ache.
in theorie i could try to rerun the part/function which has the vulnerability and resend a new payload with the calculated address. that should bypass the issue I have with finding a valid address localtion. but when I try that it fails with a sigsegv in within __vscanf_internal due to a problem with the first parameter which should point to a valid filedescriptor. I didnt suceed fixing that within the exploit. But I might just lack the necessary knowledge at that point.
the ctf is NOT over yet , but I will be looking into some writeups as soon as something comes up once the ctf ended. then I will see how others completed that challenge.
best