Skip to content

Conversation

@ulexec
Copy link

@ulexec ulexec commented Jan 4, 2019

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.

* 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)
Copy link
Owner

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 ?
Copy link
Owner

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);
Copy link
Owner

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, &section) == ELF_ITER_OK) {
if (host->e_class == ELFCLASS32) {
Elf32_Shdr *shdr = &host->shdr32[s_iter.index-1];
if (shdr->sh_offset > host->text_offset) {
Copy link
Owner

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];
Copy link
Owner

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)
Copy link
Owner

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.

bool elf_read_offset(elfobj_t *, uint64_t, uint64_t *, typewidth_t);


bool elf_has_header(const char *, bool *, elf_error_t *);
Copy link
Owner

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.

@ahhh
Copy link

ahhh commented Jan 22, 2019

@ulexec and @elfmaster we could also use this great work on a back door factory rewrite as libraries in golang: https://github.com/Binject/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants