SLAE x86 - Assignment 0x4
Custom Shellcode Encoder
Objectives
- Create a custom encoding scheme
- PoC using execve-stack as the shellcode to encode with the schema and execute
Overview
Shellcode encoding is used to make a shellcode looks gibberish or mask the original functionality. One use-case is evading antivirus or related products. During the execution of the shellcode, the first part of it will decode the encoded part of the main shellcode then execute once done.
Schema
The schema utilized for this assignment is plain and simple, but a good exercise to implement the decoder in the nasm code. Below are the steps done:
- iterate throught the shellcode bytes and check:
- if even, add 1
- if not, subtract 1
- once done with all the shellcode bytes, it will reverse the arrangement
- first byte will be the last, the last byte will be the first, and so on.
The following Ruby script do this implementation, as well as compile the nasm code which has the decoder(this will be discussed in the next section):
|
|
Decoder
The decoder will simply reverse the operations done by the encoder. This will comprise of the following steps:
- reverse the arrangement of the shellcode bytes
- iterate through the shellcode bytes and check:
- if odd, subtract 1
- if not, add 1
Below is the nasm code implementation of the decoder with inline comments for further explanation:
|
|
Script usage and testing
This blog post has been created for completing the requirements of the SecurityTube Linux Assembly Expert certification: http://securitytube-training.com/online-courses/securitytube-linux-assembly-expert/
Student ID: SLAE - 1558