Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/data/utilities/encrypted_payload/AdjustStack.asm
Views: 11780
/*1* This code is provided under the 3-clause BSD license below.2* ***********************************************************3*4* Copyright (c) 2013, Matthew Graeber5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:8*9* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.10* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.11* The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission.12*13* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.14*/1516; Author: Matthew Graeber (@mattifestation)17; License: BSD 3-Clause18; Syntax: MASM19; Build Syntax: ml64 /c /Cx AdjustStack.asm20; Output: AdjustStack.obj21; Notes: I really wanted to avoid having this external dependency but I couldnt22; come up with any other way to guarantee 16-byte stack alignment in 64-bit23; shellcode written in C.2425extern ExecutePayload26global AlignRSP ; Marking AlignRSP as PUBLIC allows for the function27; to be called as an extern in our C code.2829segment .text3031; AlignRSP is a simple call stub that ensures that the stack is 16-byte aligned prior32; to calling the entry point of the payload. This is necessary because 64-bit functions33; in Windows assume that they were called with 16-byte stack alignment. When amd6434; shellcode is executed, you cant be assured that you stack is 16-byte aligned. For example,35; if your shellcode lands with 8-byte stack alignment, any call to a Win32 function will likely36; crash upon calling any ASM instruction that utilizes XMM registers (which require 16-byte)37; alignment.3839AlignRSP:40push rsi ; Preserve RSI since were stomping on it41mov rsi, rsp ; Save the value of RSP so it can be restored42and rsp, 0FFFFFFFFFFFFFFF0h ; Align RSP to 16 bytes43sub rsp, 020h ; Allocate homing space for ExecutePayload44call ExecutePayload ; Call the entry point of the payload45mov rsp, rsi ; Restore the original value of RSP46pop rsi ; Restore RSI47ret ; Return to caller484950