Method one, with MOV, code:
Hello_mov.asm
section. Data
msg db "Hello, world!, 0xA
len equ $-Msg section
. Text
Global _start< C5/>_start:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 0x80
mov ebx, 0
mov eax, 1< C13/>int 0x80
Method Two, with XOR, code:
Hello_xor.asm
section. Data
msg db "Hello, world!, 0xA
len equ $-Msg section
. Text
Global _s Tart
_start:
xor eax,eax
xor ebx,ebx
xor ecx,ecx
xor Edx,edx
mov dl, len
mov ecx, MSG
mov bl, 1
mov al, 4
int 0x80
mov bl, 0
mov al, 1
int 0x80
After compiling the connection, then disassemble and look at the
[Root@localhost shellcode]# nasm-f elf hello_mov.asm
[root@localhost shellcode]#
[root@localhost shellcode]# Ld-o Hello_mov hello_mov.o
[root@localhost shellcode]#
[root@localhost shellcode]#] [
root@localhost shellcode]#/hello_mov
Hello, world!
. [Root@localhost shellcode]# objdump-d Hello_mov
Hello_mov: file format elf32-i386
disassembly of section. Text:
08048080 <_start>:
8048080: ba 0e mov $0xe,%edx
8048085: B9 A4 $0x80490a4,%ecx
804808a: bb mov $0x1,%ebx
804808f: B8 mov $0x4,%eax
8048094: cd int $0x80
8048096: BB 00 00 80 mov $0x0,%ebx
804809b: b8 mov $0x1,%eax
80480a0: CD int $0x80
[Root@localhost shellcode]# nasm-f elf hello_xor.asm [root@localhost shellcode]# ld-o hello_xor hello_xor.o [root@local
Host shellcode]#./hello_xor Hello, world! [Root@localhost shellcode]# objdump-d hello_xor hello_xor:file format elf32-i386 disassembly of section. text:0 8048080 <_start>: 8048080:31 c0 xor%eax,%eax 8048082:31 db x or%EBX,%EBX 8048084:31 C9 xor%ecx,%ecx 8048086:31 D2 xor%e Dx,%edx 8048088:b2 0e mov $0xe,%dl 804808a:b9 9c mov $0x804909c, %ECX 804808F:B3 mov $0x1,%bl 8048091:b0 mov $0x4,%al 8048 093:CD int $0x80 8048095:B3 mov $0x0,%bl 8048097:b0 mov $0x1,%al 8048099:cd int $0x80 [root@localHost shellcode]#
Compared to the following:
MOV ecx,0
is 5 bytes, while
xor ecx,ecx
is 2 bytes
So, I see the general Shellcode code, are using XOR eax,eax instead of MOV eax,0