GithubHelp home page GithubHelp logo

anthrax3 / nimlinewhispers2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajpc500/nimlinewhispers2

0.0 1.0 0.0 12 KB

A tool for converting SysWhispers2 syscalls for use with Nim projects

Python 40.64% Nim 59.36%

nimlinewhispers2's Introduction

             %              ..%%%%%#               %/.                  
           /%%%%%,.%%%%%%%%%%%%%%%%%%%%%%%%%%%%.%%%%%%                  
       . #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.               
  %%*.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ,%%         
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.         
    #%%%%%%%%%%%%%%.                         %%%%%%%%%%%%%%%%           
      %%%%%%%(                                     %%%%%%%%%            
    &   %%#                                           .%%  ..           
     &&.                          .                     . #&            
      &&&&.               . %&&&&&&&&.                 &&&&             
       &&&&&&&.. .   . (&&&&&&&&&&&&&&&&&%. .     .&&&&&&&              
       .%&&&&&&&&&&&&&&&&&&&&& ___  &&&&&&&&&&&&&&&&&&&&& 
         #&&&&&&&&&&&&&&&&&&& |__ \  &&&&&&&&&&&&&&&&&&&
           ,&&&&&&&&&&&&&&&&&    ) | &&&&&&&&&&&&&&&&&
               &&&&&&&&&&&&&&   / /  &&&&&&&&&&&&&&
                   &&&&&&&&&&  / /_  &&&&&&&&&&
                          %&& |____| &&.                                  
                                            NimlineWhispers2
                                            @ajpc500 2021

NimlineWhispers2

Originally inspired by Outflank's InlineWhispers tool, NimlineWhispers2 processes output from SysWhispers2 to provide compatible inline assembly for use in Nim projects.

As with the original NimlineWhispers, this project also parses the SysWhispers2 header file output to include function return types and arguments in the outputted inline assembly. Everything is then output into a single Nim file including an emit block with the SysWhispers2 methods, plus the defined functions.

NOTE: NimlineWhispers 1 can be found here.

How do I set this up?

  • Clone this repository including the forked SysWhispers2 sub module.
    • git clone --recurse-submodules https://github.com/ajpc500/NimlineWhispers2.git
  • Update which functions you required in functions.txt.
  • Run python3 NimlineWhispers2.py (additional flags listed below) to generate the inline assembly (syscalls.nim) file - example in the repo.
  • Add include syscalls to your Nim project.

An example of integrating NimlineWhispers2 output with your project can be seen in this repo.

Randomised Function Names (same functionality as NW1)

To evade detection based on the presence of function names in our Nim executables (as outlined in @ShitSecure's blog here), NimlineWhispers2 can be run with a --randomise flag, as follows:

python3 .\NimlineWhispers2.py --randomise --nobanner
[i] Function filter file "functions.txt" contains 6 functions.

[i] Using SysWhispers2 to generate asm stubs...
Complete! Files written to:
        nimlinewhispers.h
        nimlinewhispers.c
        nimlinewhispersstubs.asm

[i] Found return types for 6 functions.

[i] Producing randomised function mapping...
        NtResumeThread -> vWhUCQWffAEdMboE
        NtAllocateVirtualMemory -> SIitcDuyPGMirHPr
        NtClose -> uWZzTmdnlNmvteiL
        NtCreateThreadEx -> PDoWbNOwYbDDAcmW
        NtOpenProcess -> vWfwKlChxKZOutiX
        NtWriteVirtualMemory -> wItyVDPJWcFUqTNK

[+] Success! Outputted to syscalls.nim

For ease of integration, the mapping shown in the command-line is added as a comment in the outputted syscalls.nim file (just above the functions and below the SW2 methods). As below (including the first function to demonstrate the output):

...

# NtResumeThread -> vWhUCQWffAEdMboE
# NtAllocateVirtualMemory -> SIitcDuyPGMirHPr
# NtClose -> uWZzTmdnlNmvteiL
# NtCreateThreadEx -> PDoWbNOwYbDDAcmW
# NtOpenProcess -> vWfwKlChxKZOutiX
# NtWriteVirtualMemory -> wItyVDPJWcFUqTNK

proc vWhUCQWffAEdMboE*(ThreadHandle: HANDLE, PreviousSuspendCount: PULONG): NTSTATUS {.asmNoStackFrame.} =
    asm """
	mov [rsp +8], rcx 
...

Notably your function definitions such as the below will need to be updated with the randomised names too.

EXTERN_C NTSTATUS NtOpenProcess(
	OUT PHANDLE ProcessHandle,
	IN ACCESS_MASK DesiredAccess,
	IN POBJECT_ATTRIBUTES ObjectAttributes,
	IN PCLIENT_ID ClientId OPTIONAL);

Should become:

EXTERN_C NTSTATUS sjGfpzWwEqIMryMW(
	OUT PHANDLE ProcessHandle,
	IN ACCESS_MASK DesiredAccess,
	IN POBJECT_ATTRIBUTES ObjectAttributes,
	IN PCLIENT_ID ClientId OPTIONAL);

syscalls_rand.nim is included as an example output of this randomisation function.

Limitations

  • 64-bit only.

Credits

nimlinewhispers2's People

Contributors

ajpc500 avatar

Watchers

 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.