Better HN
topnewbestaskshowjobs
Log inSign up

dillstead

15 karma · joined Jul 29, 2025 (1y ago) · 6 submissions

Submissions

comment 1y ago · link · parent

I wouldn't be surprised if this gets flagged but I haven't tried it.

comment 1y ago · link · parent

You're right, you definitely can strip away the section headers. Notice that there's always a dynamic segment? If there wasn't, stripping away the section headers would make it very difficult to locate this very important piece of an ELF binary.

I had to make sure that I always inserted a page size multiple of bytes into the executable which can add up to a page of unused padding in addition to the thunk and chunk.

comment 1y ago · link · parent

Good point! I was aware that there are certain circumstances in which argv[0] might not contain the path to the executable but I didn't bother to look for an alternative. When I get a chance, I'll incorporate your suggestion. Thanks.

Thanks for sending your link, I'll take a look.

comment 1y ago · link · parent

Yes, I've implemented this technique before at my job. Relocating assembly instructions especially those that contain branching logic can be tricky as the offsets have to be recomputed or a new instruction needs to be used instead. More often that not, you may not have enough space for that new instruction.

comment 1y ago · link · parent

I wrote the project entirely for fun, as a learning experience and because of that I have not extensively tested it. At the moment only ELF files of type ET_EXEC can be injected.

I was careful to only inject the thunk (the code that loads the actual relocatable code chunk the the user injects) into the available padding at the end of the text segment, injecting anything larger runs the risk of "sliding" the next segment (usually the data segment) over thereby breaking references to static data from code.

6.

Show HN: ELF Injector(github.com ↗)

39 points · by dillstead · 1y ago · 13 comments