Coder Social home page Coder Social logo

idov31 / functionstomping Goto Github PK

View Code? Open in Web Editor NEW
669.0 18.0 95.0 593 KB

Shellcode injection technique. Given as C++ header, standalone Rust program or library.

Home Page: https://idov31.github.io/2022/01/28/function-stomping.html

License: GNU General Public License v3.0

C++ 35.72% YARA 2.91% Rust 61.37%
cpp rust attack shellcode-injection shellcode cybersecurity cyber methodology windows injection

functionstomping's Introduction

FunctionStomping

image image image

Description

This is a brand-new technique for shellcode injection to evade AVs and EDRs. This technique is inspired by Module Stomping and has some similarities. As to this date (23-01-2022) also hollows-hunter doesn't find it.

The biggest advantage of this technique is that it isn't overwritting an entire module or pe, just one function and the target process can still use any other function from the target module.

The disadvantage is that it won't work for every function in the wild (but it will work for most of them), the exact explanation is in my blog: The Good, The Bad And The Stomped Function.

NOTE: It is possible that AV will flag this, if the signature is a signature of msfvenom/metasploit it is fine! you just need to change the shellcode or encrypt it.

UPDATE: Apperantly this isn't the first PoC avaliable and RastaMouse wrote a blog post that is a similar thing in C#.

Usage

You either include the header to your program like this:

#include "functionstomping.hpp"

int main() {
    // Just get the pid in any way and pass it to the function.
    DWORD pid = 3110;
    FunctionStomping(pid);
    return 0;
}

Or use the rust program:

cd functionstomping
cargo b
functionstomping.exe <pid>

After you ran this program you MUST call the function from the remote process! (If you used the default function CreateFile then you must call to it from the remote process!).

Setup

Currently, the shellcode to run is just to pop a calculator, but all you need to do is replace the unsigned char shellcode[] with your shellcode. I used C++ 17 and VS2019 to compile the program with the C++ header and rust version 2021 to compile the rust program (you can see the dependencies in the Cargo.toml).

POC

Disclaimer

I'm not responsible in any way for any kind of damage that is done to your computer / program as cause of this project. I'm happily accept contribution, make a pull request and I will review it!

Acknowledgments

ModuleStomping

Masking Malicious Memory by CyberArk

RastaMouse's Version

functionstomping's People

Contributors

idov31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

functionstomping's Issues

functionstomping architecture

Hello @Idov31

I am currently studying slowly on related subjects and I am new to Rust, how do I compile this for 64bits?

functionstomping.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

Many thanks,
Best regards,
Federico

Notepad.exe throwing Unhandled Exception: System.AccessViolationException

Hello @Idov31

Many thanks for your previous advice as those allowed me to make some little progress. I have tried the C++ code as well and I am facing the following challenge. Even when I am trying to put a breakpoint to debug the code. I have tried with the POC shellcode to spawn Calc and generated other examples with reverse shells in case that was the issue. Tested with the classic Windows calculator.

Many thanks,
Kind regards,
Federico

Microsoft Windows [Version 10.0.19045.3086]

C:\Users\federico\source\repos\test\x64\Release>test.exe
[+] Got process handle!
[+] Got function base!
[+] Changed protection to RW to write the shellcode.
[+] Successfuly stomped the function!
[+] Changed protection to WCX to run the shellcode!
[+] Shellcode successfuly injected!

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at FunctionStomping(UInt32 pid) in C:\Users\federico\source\repos\test\functionstomping.hpp:line 41
at mainCRTStartup()

[BUG] Failed to change protection [0]

Hello, I'm currently studying some codes and I ended up here.

I use windows x64, I had to compile the cpp using the "-DUNICODE" flag to be able to compile, but when I run the console it does not inject any pid and brings this error:

[+] Got process handle!
[+] Got function base!
[-] Failed to change protection: 0

I tried in notepad and others, in rust when I compile it says that this program is compatible with 32bits and not x64, so the normal "cargo b" instruction doesn't work.

I tried various processes from notepad to others and it doesn't work
Screenshot_128
.

Edit:
I was able to resolve the architecture error(Windows 10 x64) in rust by running the following commands:
rustup target add x86_64-pc-windows-gnu
cargo build --target x86_64-pc-windows-gnu

After the test, the calc does not open but in the console everything seems normal, I will continue the tests
The message shows the following
Screenshot_130
:

Possible with .net assembly ?

Hi , is your beautiful peace of work working with .net assembly ?

Im trying to run a .net assembly shellcode generated with the donuts tools from TheWover.
https://github.com/TheWover/donut

the .net PE i converted is a asyncrat PE, when i try to inject it inside a process (i had to remove the max shellcode lengh because shellcode is 147k bytes long) but i get no connection back / the asssembly is not starting ?

is this even possible to work with a .net PE?

sorry for retarded question but im really noy good with shellcode stuff.

Possible to have > 0x1000 size?

Hello, neat idea you found there.
Is it possible to have more then 4096 bytes available for the shellcode or is it max?
If more is not possible, would it be possible to split it across more functions to achieve the goal?

[QUESTIONS] Some victim processes crash without execution

First of all, thanks for your work and publishing it along with the very interesting blog post.

I've been playing a bit with your POC, especially the Rust version, and there is something I'm not fully getting. Depending on the victim process, I get the following results:

  • Majority of processes (e.g notepad): when the stomped function is called the shelllcode executes (calc pops open) and the victim process crashes with an access violation error.
  • Some processes (e.g explorer.exe): when the stomped function is called the process crashes with an access violation error, but the shellcode does not seem to execute (nothing happens, no calc).

I've tried with a custom shellcode and by changing the targeted function in kernel32.dll but I always get the same results. So my questions are:

  • Do you know why for some process the shellcode will not execute, the process will just crash ? (function used ? bad shellcode ?)
  • Do you have an idea to get reliable shellcode execution on all processes ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.