chore: efl -> elf
This commit is contained in:
parent
fa004f3a6a
commit
ee6e39f716
|
@ -22,7 +22,7 @@ typedef struct payload
|
||||||
size_t len;
|
size_t len;
|
||||||
} t_payload;
|
} t_payload;
|
||||||
|
|
||||||
typedef struct efl_content
|
typedef struct elf_content
|
||||||
{
|
{
|
||||||
long unsigned int file_size;
|
long unsigned int file_size;
|
||||||
char *file_path;
|
char *file_path;
|
||||||
|
@ -31,16 +31,17 @@ typedef struct efl_content
|
||||||
Elf64_Phdr *Phdr;
|
Elf64_Phdr *Phdr;
|
||||||
Elf64_Shdr *Shdr;
|
Elf64_Shdr *Shdr;
|
||||||
char *extra_data;
|
char *extra_data;
|
||||||
} t_efl_content;
|
} t_elf_content;
|
||||||
|
|
||||||
// utils.c
|
// utils.c
|
||||||
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size);
|
void *fetch(char *file, unsigned long file_size, unsigned long offset_to_data, unsigned long supposed_data_size);
|
||||||
int ft_put_error(char *str);
|
int ft_put_error(char *str);
|
||||||
|
|
||||||
// woody.c
|
// woody.c
|
||||||
int prepare_injection(t_efl_content *woody);
|
int prepare_injection(t_elf_content *woody);
|
||||||
|
|
||||||
// encrypt.c
|
// encrypt.c
|
||||||
void encrypt(char *file, unsigned long int offset, unsigned long int size);
|
void encrypt(char *file, unsigned long int offset, unsigned long int size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "../includes/woody.h"
|
#include "../includes/woody.h"
|
||||||
|
|
||||||
int get_elf_file(t_efl_content *woody)
|
int get_elf_file(t_elf_content *woody)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
off_t off;
|
off_t off;
|
||||||
|
@ -32,7 +32,7 @@ int get_elf_file(t_efl_content *woody)
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_efl_content woody;
|
t_elf_content woody;
|
||||||
if (ac != 2)
|
if (ac != 2)
|
||||||
{
|
{
|
||||||
return ft_put_error("Woody_woodpacker take 1 argument\n");
|
return ft_put_error("Woody_woodpacker take 1 argument\n");
|
||||||
|
@ -42,4 +42,5 @@ int main(int ac, char **av)
|
||||||
if (ret == EXIT_FAILURE)
|
if (ret == EXIT_FAILURE)
|
||||||
return ret;
|
return ret;
|
||||||
return prepare_injection(&woody);
|
return prepare_injection(&woody);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
srcs/woody.c
27
srcs/woody.c
|
@ -27,7 +27,7 @@ int save_elf(char *path, char *file, unsigned long int size)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_load_segment(t_efl_content *woody, int start, bool executable)
|
int get_load_segment(t_elf_content *woody, int start, bool executable)
|
||||||
{
|
{
|
||||||
for (int i = start; i < woody->Ehdr->e_phnum; i++)
|
for (int i = start; i < woody->Ehdr->e_phnum; i++)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ int get_load_segment(t_efl_content *woody, int start, bool executable)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void offset_sections(t_efl_content *woody, unsigned int from, unsigned int offset_ammount)
|
void offset_sections(t_elf_content *woody, unsigned int from, unsigned int offset_ammount)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < woody->Ehdr->e_phnum; i++)
|
for (int i = 0; i < woody->Ehdr->e_phnum; i++)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ void offset_sections(t_efl_content *woody, unsigned int from, unsigned int offse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t create_codecave(t_efl_content *woody, Elf64_Phdr *load_segment, t_payload *payload)
|
size_t create_codecave(t_elf_content *woody, Elf64_Phdr *load_segment, t_payload *payload)
|
||||||
{
|
{
|
||||||
const unsigned int page_size = 4096; // getpagesize(); not authorized
|
const unsigned int page_size = 4096; // getpagesize(); not authorized
|
||||||
unsigned int padding_size = ((payload->len / page_size) + 1) * page_size;
|
unsigned int padding_size = ((payload->len / page_size) + 1) * page_size;
|
||||||
|
@ -93,12 +93,12 @@ t_payload *get_payload()
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
int insert_payload(t_efl_content *woody, t_payload *payload, size_t payload_position)
|
int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_position)
|
||||||
{
|
{
|
||||||
char *ptr = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len);
|
char *ptr = ft_strnstr_nullterminated(payload->payload, JUMP, payload->len);
|
||||||
if (ptr)
|
if (ptr)
|
||||||
{
|
{
|
||||||
int32_t jmp_index = ptr - payload->payload;
|
int32_t jmp_index = ptr - payload->payload;
|
||||||
int32_t jump_value = ((payload_position + payload->len) - woody->Ehdr->e_entry) * -1;
|
int32_t jump_value = ((payload_position + payload->len) - woody->Ehdr->e_entry) * -1;
|
||||||
|
|
||||||
ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
||||||
|
@ -108,19 +108,19 @@ int insert_payload(t_efl_content *woody, t_payload *payload, size_t payload_posi
|
||||||
printf("Code cave start = %ld (%lx)\n", payload_position, payload_position);
|
printf("Code cave start = %ld (%lx)\n", payload_position, payload_position);
|
||||||
printf("Payload size = %ld (%lx)\n", payload->len, payload->len);
|
printf("Payload size = %ld (%lx)\n", payload->len, payload->len);
|
||||||
printf("Backwar d offset = %d (%x)\n", jump_value, jump_value);
|
printf("Backwar d offset = %d (%x)\n", jump_value, jump_value);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void inject(t_efl_content *woody)
|
void inject(t_elf_content *woody)
|
||||||
{
|
{
|
||||||
t_payload *payload = get_payload();
|
t_payload *payload = get_payload();
|
||||||
|
|
||||||
int i = get_load_segment(woody, 0, true);
|
int i = get_load_segment(woody, 0, true);
|
||||||
int j = get_load_segment(woody, i + 1, false);
|
int j = get_load_segment(woody, i + 1, false);
|
||||||
|
|
||||||
size_t code_cave_size = woody->Phdr[j].p_offset - (woody->Phdr[i].p_offset + woody->Phdr[i].p_filesz);
|
size_t code_cave_size = woody->Phdr[j].p_offset - (woody->Phdr[i].p_offset + woody->Phdr[i].p_filesz);
|
||||||
size_t payload_position;
|
size_t payload_position;
|
||||||
printf("load position = : %ld (%lx)\n", woody->Phdr[i].p_offset, woody->Phdr[i].p_offset);
|
printf("load position = : %ld (%lx)\n", woody->Phdr[i].p_offset, woody->Phdr[i].p_offset);
|
||||||
|
@ -144,7 +144,7 @@ void inject(t_efl_content *woody)
|
||||||
printf("New entry = %ld (%lx)\n", woody->Ehdr->e_entry, woody->Ehdr->e_entry);
|
printf("New entry = %ld (%lx)\n", woody->Ehdr->e_entry, woody->Ehdr->e_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_elf_sections(t_efl_content *woody)
|
int get_elf_sections(t_elf_content *woody)
|
||||||
{
|
{
|
||||||
woody->Ehdr = (Elf64_Ehdr *)fetch(woody->file, woody->file_size, 0, sizeof(Elf64_Ehdr));
|
woody->Ehdr = (Elf64_Ehdr *)fetch(woody->file, woody->file_size, 0, sizeof(Elf64_Ehdr));
|
||||||
if (!woody->Ehdr || !elf_magic_numbers(woody->file) || woody->Ehdr->e_ident[EI_CLASS] != ELFCLASS64)
|
if (!woody->Ehdr || !elf_magic_numbers(woody->file) || woody->Ehdr->e_ident[EI_CLASS] != ELFCLASS64)
|
||||||
|
@ -178,7 +178,7 @@ int get_elf_sections(t_efl_content *woody)
|
||||||
// if (Sshstrtab == NULL)
|
// if (Sshstrtab == NULL)
|
||||||
// return ft_put_error("Corrupted file");
|
// return ft_put_error("Corrupted file");
|
||||||
|
|
||||||
// Elf64_Shdr *strtab_header = (Elf64_Shdr *)fetch(woody->file, woody->file_size, woody->Ehdr->e_shoff + (symbols_table->sh_link * woody->Ehdr->e_shentsize), sizeof(Elf64_Shdr));
|
// Elf64_Shdr *strtab_header = (Elf64_Shdr *)fetch(woody->file, woody->file_size, woody->Ehdr->e_shoff + (symbols_table->sh_link * woody->Ehdr->e_shentsize), sizeof(Elf64_Shdr));
|
||||||
// if (!strtab_header)
|
// if (!strtab_header)
|
||||||
// return ft_put_error("Corrupted file");
|
// return ft_put_error("Corrupted file");
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ int get_elf_sections(t_efl_content *woody)
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int prepare_injection(t_efl_content *woody)
|
int prepare_injection(t_elf_content *woody)
|
||||||
{
|
{
|
||||||
int elf_statut = get_elf_sections(woody);
|
int elf_statut = get_elf_sections(woody);
|
||||||
if (elf_statut)
|
if (elf_statut)
|
||||||
|
@ -211,4 +211,5 @@ int prepare_injection(t_efl_content *woody)
|
||||||
save_elf("woody", woody_file, woody->file_size);
|
save_elf("woody", woody_file, woody->file_size);
|
||||||
free(woody_file);
|
free(woody_file);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue