-
Notifications
You must be signed in to change notification settings - Fork 65
Feature/code injection #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| * Creates an elf object. initial content can be specified to contain a given ELF file. | ||
| */ | ||
| bool | ||
| elf_create_object(const char *path, struct elfobj *obj, struct elfobj *copy, size_t size, uint64_t load_flags, elf_error_t *error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cut off before 80 chars, then when you continue on the next line do 4 spaces i.e.
bool some_function(char *test, int arg2, int arg3,
struct test *tp)
{```
| } | ||
| } | ||
| memcpy(dest_mem, host->mem, code_size); | ||
| memcpy(dest_mem + code_size, target->mem, target->size > payload_size ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only skip 4 spaces on the next line to keep inline with our NetBSD style.
| memcpy(dest_mem, host->mem, code_size); | ||
| memcpy(dest_mem + code_size, target->mem, target->size > payload_size ? | ||
| payload_size : target->size); | ||
| memcpy(dest_mem + host->data_offset, host->mem + host->data_offset - payload_size, host->size - code_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep within 80 chars, then newline and 4 spaces.
| while (elf_section_iterator_next(&s_iter, §ion) == ELF_ITER_OK) { | ||
| if (host->e_class == ELFCLASS32) { | ||
| Elf32_Shdr *shdr = &host->shdr32[s_iter.index-1]; | ||
| if (shdr->sh_offset > host->text_offset) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a blank line after defining any variables, so this line of code should have one blank line before it.
| while (elf_segment_iterator_next(&p_iter, &segment) == ELF_ITER_OK) { | ||
| if (segment.offset == host->text_offset && segment.type == PT_LOAD) { | ||
| if (host->e_class == ELFCLASS32) { | ||
| Elf32_Phdr *phdr = &host->phdr32[p_iter.index-1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make a blank line after this line before the line of code. And follow this whenever you define or declare a variable, always make sure there is a blank line before the next line of code. There are several places but I wont point them all out. Its an easy fix. Sorry to be a pain in the ass, I try to follow it to a tee myself.
| */ | ||
| bool | ||
| elf_inject_code(struct elfobj *host, struct elfobj *target, uint64_t *payload_offset, | ||
| uint64_t injection_flags, elf_error_t *error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use only 4 spaces when you move to the next line.
include/libelfmaster.h
Outdated
| bool elf_read_offset(elfobj_t *, uint64_t, uint64_t *, typewidth_t); | ||
|
|
||
|
|
||
| bool elf_has_header(const char *, bool *, elf_error_t *); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you get a chance put comments describing each function and its arguments. I need to do this too on some of mine. This is where we document our API for other developers who want to work on it.
|
@ulexec and @elfmaster we could also use this great work on a back door factory rewrite as libraries in golang: https://github.com/Binject/ |
Implemented basic code injection support. This implies mainly 3 techniques
1 - Text segment padding injection
2 - Reverse text segment injection
3 - Data segment injection
It's also implemented helper generic function to convert offset to addresses and vice-versa as-well as helper functions to open stubs from disk.