frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Show HN: ELF Injector

https://github.com/dillstead/elf_injector
36•dillstead•12h ago
The ELF Injector allows you to "inject" arbitrary-sized relocatable code chunks into ELF executables. The code chunks will run before the original entry point of the executable runs.

Included in the project are sample chunks as well as a step-by-step tutorial on how it works.

It's a mix of C and assembly and currently runs on 32-bit ARM though it's easy to port to other architectures.

Comments

Retr0id•12h ago
One of the challenges of ELF injection/infection is that you might break assumptions made by the original ELF regarding its layout, particularly for dynamic ELFs (which often parse .dynamic at runtime, etc.)

How many different target ELFs have you tried it with, and are there any that don't work?

dillstead•12h ago
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.

etune•10h ago
ATOM could inject code before or after any basic block in a program: https://dl.acm.org/doi/abs/10.1145/178243.178260. The general technique, IIRC, was to replace the first instruction of the basic block with a jump to code that contained your new code and then the overwritten instructions, and then jump back into the original code.
dillstead•9h ago
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.
nicholasmoser•8h ago
This is also similar to what is done with video game modification (think Gecko, Game Shark, Game Genie).
viccis•8h ago
How does it fare on Virustotal?

Most of the these projects (often intended as packers or similar obfuscation techniques for malware) that I've seen are cool but get flagged aggressively.

matheusmoreira•7h ago
Always cool to see people hacking ELF! I see you're using argv[0] to find the executable file. This is fragile because argument vector contents are arbitrary and controlled entirely by the parent process. In other words, argv[0] could contain anything, even an empty string. If you're targeting Linux specifically, there's a better way: /proc/self/exe.

I created something similar to your tool: an ELF embedder. It's for arbitrary data rather than native code injection.

I leveraged ELF segments to get the kernel to mmap the data into memory on my behalf, no file I/O needed. The auxvec allows the program to reach its own program header table. From there it's just a matter of finding the right segment.

https://www.matheusmoreira.com/articles/self-contained-lone-...

My programming language's interpreter introspects into its own ELF header, finds the embedded segments and uses them to load data and code from inside itself.

I'm not entirely sure whether this approach is applicable to your case but it might be worth a try. My embedding tool could just as easily map in executable segments.

dillstead•6h ago
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.

wahern•3h ago
IME it's far more likely for a program to run in an environment lacking /proc (e.g. some containers) than for argv[0] to be NULL, empty, or lying. Even /proc/self/exe can been used in an exploit chain (https://lwn.net/Articles/920384/). And there have been many other /proc-related exploits, which is why it's often a good idea to not even mount /proc at all rather than just mask /proc subtrees.

But even if /proc/self/exe is visible, it might not be possible to open it. For example, you can execute a binary residing in anonymous memory (memfd) using fexecve(2), or the executable file could have been deleted immediately after execution. AFAIU, /proc/self/exec is generated as a symlink rather than exposing the file object directly (cf. BSD /dev/fd), so opening it can fail.

The easy fix is to just simply fail if argv[0] is NULL or empty, but if one is a glutton for punishment and wants to be "robust", /proc/self/exe support could be added as a (preferred) alternative rather than a substitute mechanism.

wahern•1h ago
EDIT: I was wrong, /proc/self/exe is directly openable, even if the path returned by readlink doesn't exist.
nekitamo•7h ago
Interesting, I also had to solve this problem about a decade ago when writing a binary packer for Android .so libraries. I ended up moving the first few Pheaders around to make space for a new entry in the Elf32_Phdr table, and then used that to inject a new code segment at the end of the file. Due to padding constraints this could sometimes add a significant amount of null bytes to the binary just for padding.

I also made my code execute before the entry point by specifying it as DT_INIT in the dynamic section. This way you don't have to modify the entry point pointer or call it after your unpacking stub is done decompressing the binary in memory.

Your solution with the the thunk is much better and probably avoids a lot of the complexity I encountered in moving segment headers around! Elf is a tight format unlike PE. Not a single byte goes to waste.

Thanks for sharing your project, I learned something today!

PS one interesting piece of trivia I found was that you could strip the section header entirely from an Elf file and the OS would still load and execute it. All it needs is the segment headers. It looks like the section headers are just there as a courtesy to help tools like strip and objcopy.

dillstead•6h ago
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.

M8.7 earthquake in Western Pacific, tsunami warning issued

https://earthquake.usgs.gov/earthquakes/eventpage/us6000qw60/executive
428•jandrewrogers•3h ago•87 comments

Study mode

https://openai.com/index/chatgpt-study-mode/
752•meetpateltech•10h ago•520 comments

RIP Shunsaku Tamiya, the man who made plastic model kits a global obsession

https://JapaneseNostalgicCar.com/rip-shunsaku-tamiya-plastic-model-kits/
167•fidotron•6h ago•32 comments

URL-Driven State in HTMX

https://www.lorenstew.art/blog/bookmarkable-by-design-url-state-htmx/
112•lorenstewart•5h ago•42 comments

Launch HN: Hyprnote (YC S25) – An open-source AI meeting notetaker

159•yujonglee•11h ago•84 comments

Two Birds with One Tone: I/Q Signals and Fourier Transform

https://wirelesspi.com/two-birds-with-one-tone-i-q-signals-and-fourier-transform-part-1/
24•teleforce•4h ago•2 comments

USB-C for Lightning iPhones

https://obsoless.com/products/iph0n3-usb-c-protection-case
84•colinprince•3d ago•70 comments

Learning basic electronics by building fireflies

http://a64.in/posts/learning-basic-electronics-by-building-fireflies/
194•signa11•10h ago•55 comments

iPhone 16 cameras vs. traditional digital cameras

https://candid9.com/phone-camera/
152•sergiotapia•13h ago•195 comments

FoundationDB: From idea to Apple acquisition [video]

https://www.youtube.com/watch?v=C1nZzQqcPZw
126•zdw•4d ago•16 comments

Actual Size Online Ruler (Mm,Cm,Inches)

https://anruler.com/
4•artiomyak•2d ago•6 comments

How the brain increases blood flow on demand

https://hms.harvard.edu/news/how-brain-increases-blood-flow-demand
77•gmays•8h ago•35 comments

Show HN: I built an AI that turns any book into a text adventure game

https://www.kathaaverse.com/
208•rcrKnight•11h ago•82 comments

JavaScript decided my day starts at 9am

https://senhongo.com/blog/when-javaScript-decided-my-day-starts-at-9am
21•SenHeng•3d ago•23 comments

Dropbox Passwords discontinuation

https://help.dropbox.com/en-us/installs/dropbox-passwords-discontinuation
39•h1fra•7h ago•14 comments

ACM Transitions to Full Open Access

https://www.acm.org/publications/openaccess
133•pcvarmint•10h ago•13 comments

Irrelevant facts about cats added to math problems increase LLM errors by 300%

https://www.science.org/content/article/scienceadviser-cats-confuse-ai
333•sxv•12h ago•161 comments

Show HN: Terminal-Bench-RL: Training long-horizon terminal agents with RL

https://github.com/Danau5tin/terminal-bench-rl
106•Danau5tin•16h ago•10 comments

CodeCrafters (YC S22) is hiring first Marketing Person

https://www.ycombinator.com/companies/codecrafters/jobs/7ATipKJ-1st-marketing-hire
1•sarupbanskota•6h ago

A month using XMPP (using Snikket) for every call and chat (2023)

https://neilzone.co.uk/2023/08/a-month-using-xmpp-using-snikket-for-every-call-and-chat/
87•ColinWright•9h ago•52 comments

Microsoft Flight Simulator 2024: WebAssembly SDK

https://docs.flightsimulator.com/msfs2024/html/6_Programming_APIs/WASM/WebAssembly.htm
120•breve•3d ago•62 comments

Playing with more user-friendly methods for multi-factor authentication

https://tesseral.com/blog/i-designed-some-more-user-friendly-methods-for-multi-factor-authentication
51•noleary•1d ago•32 comments

Structuring large Clojure codebases with Biff

https://biffweb.com/p/structuring-large-codebases/
56•PaulHoule•13h ago•3 comments

My 2.5 year old laptop can write Space Invaders in JavaScript now (GLM-4.5 Air)

https://simonwillison.net/2025/Jul/29/space-invaders/
467•simonw•14h ago•324 comments

Measuring Engineering

https://fffej.substack.com/p/measuring-engineering
21•mooreds•3d ago•5 comments

Supervised fine tuning on curated data is reinforcement learning

https://arxiv.org/abs/2507.12856
42•GabrielBianconi•7h ago•14 comments

Maru OS – Use your phone as your PC

https://maruos.com/
207•fsflover•8h ago•144 comments

Elements of System Design

https://github.com/jarulraj/periodic-table
93•qianli_cs•10h ago•33 comments

Observable Notebooks 2.0 Technology Preview

https://observablehq.com/notebook-kit/
189•mbostock•13h ago•45 comments

More honey bees dying, even as antibiotic use halves

https://news.uoguelph.ca/2025/07/more-honey-bees-dying-even-as-antibiotic-use-halves/
162•pseudolus•8h ago•116 comments