Replies: 5 comments 1 reply
-
Just in case anybody is curious enough to replicate: https://github.com/pgalkin/classic_shellcode_sample. Ignore harness.c, it's a scratch file. |
Beta Was this translation helpful? Give feedback.
-
Uhm. Environment variables are null terminated strings. Not sure how can you do that |
Beta Was this translation helpful? Give feedback.
-
wait. i have a fun idea xD |
Beta Was this translation helpful? Give feedback.
-
this was the fun idea: #24275 can you test the pr and confirm the correct behaviour? :) |
Beta Was this translation helpful? Give feedback.
-
you must encode the shellcode to avoid null bytes, i pushed a nullby encoder but ragg already ships a xor encoder that may help you on that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Help me out please, I feel this must be possible. My goal: use radare2 as a harness for exploiting a classing stack overflow. ASLR disabled, stack is executable, platform is Linux x86-64. I followed this tutorial: https://www.ired.team/offensive-security/code-injection-process-injection/binary-exploitation/64-bit-stack-based-buffer-overflow
This is the target:
The suggested approach is to store the shellcode in an environment variable, and then overflowing with a padded string with the address of the shellcode at the end. This address is meant to overwrite the return address. This is how it looks:
> xxd in2.bin 00000000: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000010: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000020: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000030: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000040: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000050: 4141 4141 4141 4141 4141 4141 4141 4141 AAAAAAAAAAAAAAAA 00000060: 4141 4141 4141 4141 4ded ffff ff7f 0000 AAAAAAAAM.......
The address is
0x7fffffffed4d
. This is where the tutorial wasn't precise enough. On my machine this address gets into RIP in a rounded up form because of alignment requirement (or so I think). More specifically I get0x7fffffffed54
. This means I land a bit further than the start of my shellcode.Fine then, I have to pad with nops. How many? Well,
0x7fffffffed54 - 0x7fffffffed4d = 7
, at least this many. However, it is not possible to pad an environment variable with nops via shell, they will be stripped out. I don't understand why it happens but it does. Fine then, I'll pad with whatever but will be precise and have exactly 7 of whatever. This is my padded shellcode:This is how I set the environment variable to the shellcode above (in fish shell):
So my manual launch works and spawns the shell:
Now I want to do the same but with rarun2 (or any other radare2 tools). Conceptually this should work:
> rarun2 program=vulnerable envfile=envfile stdin=in2.bin
Where envfile is this (
PWN=<shellcode>
):It doesn't:
The 2 null bytes of the address weren't read, I notice. Ok, how about this:
Same error. How do I fix the issue with 2 null bytes not being read, and do I set the environment variable correctly using setenv or envfile options?
Are there any C harnesses that I can use instead of radare2 for this kind of exploit? I feel like this is very basic, yet there is very little solid info on the internet, most of it just casts the shellcode as a function and calls it. AI suggests I base64 encode the payload. Amusing, yes. I just want to spawn a shell on a stack overflow, that's it. Not manually, manually I can do it, it's a pain. Automatically. I launch the thing and it spawns, like a real hacker from the 90s.
Beta Was this translation helpful? Give feedback.
All reactions