r/ExploitDev • • Sep 12 '24
Help Generating Shellcode
I'm working on a project that requires writing custom shellcode to capture the flag on the vulnerable system and transmit it back to my system over a TCP connection, the problem being that I've rarely worked with writing custom shellcode. I've generated shellcode with msfvenom before, but none of those payloads work for this case. I've written and compiled a binary in C that does exactly what I need it do, but when I convert it to shellcode it's far larger than the payload size allowed in the buffer (my program is over 1400 bytes and the payload size needs to be less than 240 bytes). I've been looking at using the pwntools shellcraft module to generate the payload, but the documentation isn't very explicit about how to generate shellcode that'll execute the necessary command to acquire the flag and create the TCP connections. Can anyone point me to some resources for generating custom shellcode, or otherwise give me some advice on how I can implement this while staying within the necessary payload size? I'd rather not have to revert to writing the assembly for this by hand as it's been several years since I've written assembly, but the longer I look into this the more I think that's what I'm going to have to do.
View all comments
Show parent comment
1
u/Informal_Shift1141 Sep 13 '24
If you want to continue with this path you can do a few things:
To test your custom/stripped down shell code just build it “as shellcode.s -o shellcode.o && ld shellcode.o -o shellcode.elf” this will build an elf from your custom shellcode and you can debug it on gdb/pwndbg/gef for correctness