Generar archivo PE con códigos de shell OWASP ZSC

Como sabemos, los Shellcodes tienen usos muy diferentes, como los procesos de desarrollo de Exploit y Malwares, etc. Pero hay una pregunta: ¿podríamos compilar los Shellcodes [códigos de ensamblaje] y ejecutarlos sin inyectar dentro de otro proceso o archivo? ¡Por supuesto! Los códigos de shell son un conjunto de códigos de ensamblaje con códigos nulos eliminados o lo hacen inyectable en un proceso. 

OWASP ZSC nos permite tener códigos de desmontaje dentro del archivo generado. Podría ser utilizado para compilar un archivo de cantar. Eche un vistazo a un shellcode que generó OWASP ZSC . 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
dieciséis
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h> 
#include <string.h> 
/ * 
Este shellcode generado por ZCR Shellcoder [zsc] http://zsc.z3r0d4y.com/ 
Título: system ('nc [espacio] -v [espacio] google .com [espacio] 80 ') 
SO: linux_x86 
Codificar: ninguno 
Longitud: 74

shellcode.c: formato de archivo elf32-i386

Desmontaje de la sección .text: 
00000000 <.text>: 
   0: 6a 0b push $ 0xb 
   2: 58 pop% eax 
   3: 99 cltd    
   4: 52 push% edx 
   5: 68 90 20 38 30 push $ 0x30382090 
   a: 59 pop% ecx 
   b: c1 e9 08 shr $ 0x8,% ecx 
   e: 51 push% ecx 
   f: 68 2e 63 6f 6d push $ 0x6d6f632e 
  14: 68 6f 67 6c 65 push $ 0x656c676f 
  19: 68 76 20 67 6f push $ 0x6f672076 
  1e: 68 6e 63 20 2d empuje $ 0x2d20636e 
  23: 89 e6 mov% esp,% esi
   25: 52 push% edx 
  26: 68 90 90 2d 63 push $ 0x632d9090 
  2b: 59 pop% ecx 
  2c: c1 e9 10 shr $ 0x10,% ecx 
  2f: 51 push% ecx
   30: 89 e1 mov% esp,% ecx 
  32 : 52 push% edx 
  33: 6a 68 push $ 0x68 
  35: 68 2f 62 61 73 push $ 0x7361622f 
  3a: 68 2f 62 69 6e push $ 0x6e69622f 
  3f: 89 e3 mov% esp,% ebx 
  41: 52 push% edx 
  42: 57 push% edi 
  43: 56 push% esi
  44: 51 push% ecx 
  45: 53 push% ebx 
  46: 89 e1 mov% esp,% ecx 
  48: cd 80 int $ 0x80



ejemplo de compilación: gcc -ggdb -static -fno-stack-protector -z execstack -mpreferred-stack-boundary = 2 -o shellcode_compiled shellcode.c 
* /
 
int  main () { 
unsigned  char  shellcode [] =  "\ x6a \ x0b \ x58 \ x99 \ x52 \ x68 \ x90 \ x20 \ x38 \ x30 \ xc1 \ xe9 \ x08 \ x51 \ x68 \ x2 \ x63 \ x6f \ x6d \ x68 \ x6f \ x67 \ x6c \ x65 \ x68 \ x76 \ x20 \ x67 \ x6f \ x68 \ x6e \ x63 \ x20 \ x2d \ x89 \ xe6 \ x52 \ x68 \ x90 \ x90 \ x2d \ x63 \ x63 \ xc1 \ xe9 \ x10 \ x51 \ x89 \ xe1 \ x52 \ x6a \ x68 \ x68 \ x2f \ x62 \ x61 \ x73 \ x68 \ x2f \ x62 \ x69 \ x6e \ x89 \ xe3 \ x52 \ x57 \ x56 \ x51 \ x53 \ x89 \ xe1 \ xcd \ x80 " ; 
fprintf (stdout, "Length:% d \ n \ n" , strlen (shellcode));
    (* ( void (*) ())  shellcode) (); 
}
Nuestro shellcode creado para el sistema operativo linux_x86 que ejecutará el comando nc -v google.com 80 ", y como podemos ver, hemos desensamblado el código en el comentario del archivo C.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33
Disassembly of section .text:
00000000 <.text>:
   0:    6a 0b                   push   $0xb
   2:    58                      pop    %eax
   3:    99                      cltd
   4:    52                      push   %edx
   5:    68 90 20 38 30          push   $0x30382090
   a:    59                      pop    %ecx
   b:    c1 e9 08                shr    $0x8,%ecx
   e:    51                      push   %ecx
   f:    68 2e 63 6f 6d          push   $0x6d6f632e
  14:    68 6f 67 6c 65          push   $0x656c676f
  19:    68 76 20 67 6f          push   $0x6f672076
  1e:    68 6e 63 20 2d          push   $0x2d20636e
  23:    89 e6                   mov    %esp,%esi
  25:    52                      push   %edx
  26:    68 90 90 2d 63          push   $0x632d9090
  2b:    59                      pop    %ecx
  2c:    c1 e9 10                shr    $0x10,%ecx
  2f:    51                      push   %ecx
  30:    89 e1                   mov    %esp,%ecx
  32:    52                      push   %edx
  33:    6a 68                   push   $0x68
  35:    68 2f 62 61 73          push   $0x7361622f
  3a:    68 2f 62 69 6e          push   $0x6e69622f
  3f:    89 e3                   mov    %esp,%ebx
  41:    52                      push   %edx
  42:    57                      push   %edi
  43:    56                      push   %esi
  44:    51                      push   %ecx
  45:    53                      push   %ebx
  46:    89 e1                   mov    %esp,%ecx
  48:    cd 80                   int    $0x80
Y ahora todo lo que necesitamos es Spliting ensamblado compilado los códigos de operación .
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29
 30 
31
push   $0xb
pop    %eax
cltd
push   %edx
push   $0x30382090
pop    %ecx
shr    $0x8,%ecx
push   %ecx
push   $0x6d6f632e
push   $0x656c676f
push   $0x6f672076
push   $0x2d20636e
mov    %esp,%esi
push   %edx
push   $0x632d9090
pop    %ecx
shr    $0x10,%ecx
push   %ecx
mov    %esp,%ecx
push   %edx
push   $0x68
push   $0x7361622f
push   $0x6e69622f
mov    %esp,%ebx
push   %edx
push   %edi
push   %esi
push   %ecx
push   %ebx
mov    %esp,%ecx
int    $0x80

Tenemos que guardar estos códigos dentro de un archivo y compilarlo. Luego tenemos el archivo de PE.
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45
 46
root@airz:/# cat shellcode.asm
push   $0xb
pop    %eax
cltd
push   %edx
push   $0x30382090
pop    %ecx
shr    $0x8,%ecx
push   %ecx
push   $0x6d6f632e
push   $0x656c676f
push   $0x6f672076
push   $0x2d20636e
mov    %esp,%esi
push   %edx
push   $0x632d9090
pop    %ecx
shr    $0x10,%ecx
push   %ecx
mov    %esp,%ecx
push   %edx
push   $0x68
push   $0x7361622f
push   $0x6e69622f
mov    %esp,%ebx
push   %edx
push   %edi
push   %esi
push   %ecx
push   %ebx
mov    %esp,%ecx
int    $0x80

root@airz:/# as shellcode.asm -o shellcode.o
root@airz:/# ld shellcode.o -o shellcode
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048054
root@airz:/# ./shellcode 
DNS fwd/rev mismatch: google.com != lga15s46-in-f7.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f5.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f8.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f0.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f9.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f1.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f4.1e100.net
DNS fwd/rev mismatch: google.com != lga15s46-in-f2.1e100.net
google.com [173.194.123.7] 80 (http) open
Referencias
ZeroDay Cyber ​​Research  
ZSC Página de inicio de  
OWASP 
Ali Razmjoo 

Comentarios