merge
This commit is contained in:
commit
9b39864ee8
|
@ -18,7 +18,8 @@ void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||||
return ;
|
return ;
|
||||||
if (del)
|
if (del)
|
||||||
{
|
{
|
||||||
free(lst);
|
|
||||||
del(lst->content);
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
nasm -f elf64 -o print.o print.s && ld -o print print.o && nasm -f bin -o payload print.s && hexdump -v -e '"\\\x\" 1/1 "%02x"' payload
|
|
@ -50,4 +50,5 @@ 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
|
||||||
|
|
||||||
|
|
2
print.s
2
print.s
|
@ -34,4 +34,4 @@ _start:
|
||||||
jmp 0x00000000 ;for now it needs to be the first jmp
|
jmp 0x00000000 ;for now it needs to be the first jmp
|
||||||
msg db "..WOODY..",10
|
msg db "..WOODY..",10
|
||||||
text_section dq 0xbabababababababa
|
text_section dq 0xbabababababababa
|
||||||
section_sisze dq 0xcacacacacacacaca
|
section_sisze dq 0xcacacacacacacaca
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
srcs/woody.c
13
srcs/woody.c
|
@ -1,6 +1,5 @@
|
||||||
#include "../includes/woody.h"
|
#include "../includes/woody.h"
|
||||||
|
|
||||||
|
|
||||||
int elf_magic_numbers(char *str)
|
int elf_magic_numbers(char *str)
|
||||||
{
|
{
|
||||||
return (!ft_strncmp(str, ELFMAG, SELFMAG));
|
return (!ft_strncmp(str, ELFMAG, SELFMAG));
|
||||||
|
@ -109,13 +108,13 @@ int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_posi
|
||||||
int32_t woody_index = ptr_woody - payload->payload;
|
int32_t woody_index = ptr_woody - payload->payload;
|
||||||
|
|
||||||
int32_t jmp_index = ptr_jmp - payload->payload;
|
int32_t jmp_index = ptr_jmp - payload->payload;
|
||||||
int32_t jump_value = (payload_position - woody->Ehdr->e_entry + jmp_index - 1) * -1;
|
int32_t jump_value = ((payload_position + jmp_index + 5) - woody->Ehdr->e_entry) * -1; // 5 = JUMP SIZE (OPCODE + 4 bytes operand)
|
||||||
ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
ft_memcpy(&payload->payload[jmp_index + 1], &jump_value, sizeof(jump_value));
|
||||||
|
|
||||||
int64_t text_index = ptr_text_section - payload->payload;
|
int64_t text_index = ptr_text_section - payload->payload;
|
||||||
int64_t text_value = payload_position - woody->Ehdr->e_entry + woody_index;
|
int64_t text_value = payload_position - woody->Ehdr->e_entry + woody_index;
|
||||||
ft_memcpy(&payload->payload[text_index], &text_value, sizeof(text_value));
|
ft_memcpy(&payload->payload[text_index], &text_value, sizeof(text_value));
|
||||||
|
|
||||||
int64_t section_index = ptr_section_size - payload->payload;
|
int64_t section_index = ptr_section_size - payload->payload;
|
||||||
int64_t section_value = woody->text_section->sh_size;
|
int64_t section_value = woody->text_section->sh_size;
|
||||||
ft_memcpy(&payload->payload[section_index], §ion_value, sizeof(section_value));
|
ft_memcpy(&payload->payload[section_index], §ion_value, sizeof(section_value));
|
||||||
|
@ -129,7 +128,7 @@ int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_posi
|
||||||
printf("Old entry : %ld (%lx)\n", woody->Ehdr->e_entry, woody->Ehdr->e_entry);
|
printf("Old entry : %ld (%lx)\n", woody->Ehdr->e_entry, woody->Ehdr->e_entry);
|
||||||
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)(%x)\n", jump_value, jump_value, -jump_value);
|
printf("Backward offset = %d (%x)(%x)\n", jump_value, jump_value, -jump_value);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -138,9 +137,9 @@ int insert_payload(t_elf_content *woody, t_payload *payload, size_t payload_posi
|
||||||
void inject(t_elf_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);
|
||||||
|
@ -207,6 +206,7 @@ int get_elf_sections(t_elf_content *woody)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,3 +226,4 @@ int prepare_injection(t_elf_content *woody)
|
||||||
free(woody_file);
|
free(woody_file);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue