5 ms·
I remember doing exactly this to get code injection working on GNU/Linux systems! I made a library injection library in college for some coursework, which invo
by skim_milk 5y ago
I remember doing exactly this to get code injection working on GNU/Linux systems! I made a library injection library in college for some coursework, which involved copying a C function into a code cave on a remote process and getting the remote process to execute it and return. It only works because its so bare-bones, it doesn't use try/catch and calls to other functions are possible because the function pointers are passed in through the registers and the compiled code is small enough to fit in a single page.
An example function I memcpy and run:
https://github.com/skimmilk/liblibinject/blob/master/src/liblibinject/external.cpp#L92 https://github.com/skimmilk/liblibinject/blob/master/src/lib...
- tomcam 5y agoWait does C now have try/catch?
- basementcat 5y agoIt’s called setjmp() and longjmp(). https://web.archive.org/web/20091104065428/http://www.di.unipi.it/~nids/docs/longjump_try_trow_catch.html https://web.archive.org/web/20091104065428/http://www.di.uni...
- tptacek 5y agoIt has setjmp and longjmp, so yeah.
- kragen 5y agoAs you are well aware, calling setjmp and longjmp doesn't make code non-position-independent in the way that Raymond is talking about, because setjmp saves the return address with which it was actually called. It doesn't rely on PC tables in the executable the way that (a common implementation of) C++ exception handling does. I mention this not to inform you of it (you already understand it better than I do) but to keep anyone else reading the thread from being misled.
- tomcam 5y agoYeah like me. That was my understanding but I thought perhaps C had snuck in some high level exception handling that I didn’t know about.
- skim_milk 5y agoTechnically the code being uploaded is compiled from C++ as the rest of the project is written in C++. Kind of similar to the article but in my case all I'm doing is calling a bunch of C library functions from the shellcode.